]> git.saurik.com Git - wxWidgets.git/blame - include/wx/windowptr.h
Make storing non-trivial data in wxThreadSpecificInfo possible.
[wxWidgets.git] / include / wx / windowptr.h
CommitLineData
c80d4c1e
VS
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
19namespace wxPrivate
20{
21
22struct wxWindowDeleter
23{
24 void operator()(wxWindow *win)
25 {
26 win->Destroy();
27 }
28};
29
30} // namespace wxPrivate
31
32template<typename T>
33class wxWindowPtr : public wxSharedPtr<T>
34{
35public:
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_