]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dfb/dfbptr.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / dfb / dfbptr.h
CommitLineData
b3c86150 1/////////////////////////////////////////////////////////////////////////////
52c8d32a
VS
2// Name: wx/dfb/dfbptr.h
3// Purpose: wxDfbPtr<T> for holding objects declared in wrapdfb.h
b3c86150
VS
4// Author: Vaclav Slavik
5// Created: 2006-08-09
b3c86150
VS
6// Copyright: (c) 2006 REA Elektronik GmbH
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
52c8d32a
VS
10#ifndef _WX_DFB_DFBPTR_H_
11#define _WX_DFB_DFBPTR_H_
b3c86150
VS
12
13//-----------------------------------------------------------------------------
14// wxDFB_DECLARE_INTERFACE
15//-----------------------------------------------------------------------------
16
17/**
52c8d32a 18 Forward declares wx wrapper around DirectFB interface @a name.
b3c86150 19
52c8d32a 20 Also declares wx##name##Ptr typedef for wxDfbPtr<wx##name> pointer.
b3c86150
VS
21
22 @param name name of the DirectFB interface
23 */
24#define wxDFB_DECLARE_INTERFACE(name) \
52c8d32a
VS
25 class wx##name; \
26 typedef wxDfbPtr<wx##name> wx##name##Ptr;
b3c86150
VS
27
28
29//-----------------------------------------------------------------------------
52c8d32a 30// wxDfbPtr<T>
b3c86150
VS
31//-----------------------------------------------------------------------------
32
52c8d32a
VS
33class wxDfbWrapperBase;
34
50b2d544 35class WXDLLIMPEXP_CORE wxDfbPtrBase
b3c86150
VS
36{
37protected:
52c8d32a
VS
38 static void DoAddRef(wxDfbWrapperBase *ptr);
39 static void DoRelease(wxDfbWrapperBase *ptr);
b3c86150
VS
40};
41
42/**
43 This template implements smart pointer for keeping pointers to DirectFB
52c8d32a
VS
44 wrappers (i.e. wxIFoo classes derived from wxDfbWrapper<T>). Interface's
45 reference count is increased on copying and the interface is released when
46 the pointer is deleted.
b3c86150
VS
47 */
48template<typename T>
49class wxDfbPtr : private wxDfbPtrBase
50{
51public:
52 /**
52c8d32a 53 Creates the pointer from raw pointer to the wrapper.
b3c86150
VS
54
55 Takes ownership of @a ptr, i.e. AddRef() is @em not called on it.
56 */
57 wxDfbPtr(T *ptr = NULL) : m_ptr(ptr) {}
58
59 /// Copy ctor
60 wxDfbPtr(const wxDfbPtr& ptr) { InitFrom(ptr); }
61
62 /// Dtor. Releases the interface
63 ~wxDfbPtr() { Reset(); }
64
65 /// Resets the pointer to NULL, decreasing reference count of the interface.
66 void Reset()
67 {
68 if ( m_ptr )
69 {
52c8d32a 70 this->DoRelease((wxDfbWrapperBase*)m_ptr);
b3c86150
VS
71 m_ptr = NULL;
72 }
73 }
74
52c8d32a 75 /// Cast to the wrapper pointer
b3c86150
VS
76 operator T*() const { return m_ptr; }
77
52c8d32a 78 // standard operators:
b3c86150 79
52c8d32a 80 wxDfbPtr& operator=(T *ptr)
b3c86150
VS
81 {
82 Reset();
52c8d32a
VS
83 m_ptr = ptr;
84 return *this;
b3c86150
VS
85 }
86
b3c86150
VS
87 wxDfbPtr& operator=(const wxDfbPtr& ptr)
88 {
89 Reset();
90 InitFrom(ptr);
91 return *this;
92 }
93
94 T& operator*() const { return *m_ptr; }
95 T* operator->() const { return m_ptr; }
96
97private:
98 void InitFrom(const wxDfbPtr& ptr)
99 {
100 m_ptr = ptr.m_ptr;
101 if ( m_ptr )
52c8d32a 102 this->DoAddRef((wxDfbWrapperBase*)m_ptr);
b3c86150
VS
103 }
104
105private:
106 T *m_ptr;
107};
108
52c8d32a 109#endif // _WX_DFB_DFBPTR_H_