]> git.saurik.com Git - wxWidgets.git/blob - include/wx/windowptr.h
Add lambda-friendly wxDialog::ShowWindowModalThenDo().
[wxWidgets.git] / include / wx / windowptr.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/windowptr.h
3 // Purpose: smart pointer for holding wxWindow instances
4 // Author: Vaclav Slavik
5 // Created: 2013-09-01
6 // Copyright: (c) 2013 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_WINDOWPTR_H_
11 #define _WX_WINDOWPTR_H_
12
13 #include "wx/sharedptr.h"
14
15 // ----------------------------------------------------------------------------
16 // wxWindowPtr: A smart pointer with correct wxWindow destruction.
17 // ----------------------------------------------------------------------------
18
19 namespace wxPrivate
20 {
21
22 struct wxWindowDeleter
23 {
24 void operator()(wxWindow *win)
25 {
26 win->Destroy();
27 }
28 };
29
30 } // namespace wxPrivate
31
32 template<typename T>
33 class wxWindowPtr : public wxSharedPtr<T>
34 {
35 public:
36 typedef T element_type;
37
38 wxEXPLICIT wxWindowPtr(element_type* win)
39 : wxSharedPtr<T>(win, wxPrivate::wxWindowDeleter())
40 {
41 }
42
43 wxWindowPtr() {}
44 wxWindowPtr(const wxWindowPtr& tocopy) : wxSharedPtr<T>(tocopy) {}
45
46 wxWindowPtr& operator=(const wxWindowPtr& tocopy)
47 {
48 wxSharedPtr<T>::operator=(tocopy);
49 return *this;
50 }
51
52 wxWindowPtr& operator=(element_type* win)
53 {
54 return operator=(wxWindowPtr(win));
55 }
56
57 void reset(T* ptr = NULL)
58 {
59 wxSharedPtr<T>::reset(ptr, wxPrivate::wxWindowDeleter());
60 }
61 };
62
63 #endif // _WX_WINDOWPTR_H_