]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dfb/dfbptr.h
Add more checks for Intel compiler.
[wxWidgets.git] / include / wx / dfb / dfbptr.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dfb/dfbptr.h
3 // Purpose: wxDfbPtr<T> for holding objects declared in wrapdfb.h
4 // Author: Vaclav Slavik
5 // Created: 2006-08-09
6 // Copyright: (c) 2006 REA Elektronik GmbH
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_DFB_DFBPTR_H_
11 #define _WX_DFB_DFBPTR_H_
12
13 //-----------------------------------------------------------------------------
14 // wxDFB_DECLARE_INTERFACE
15 //-----------------------------------------------------------------------------
16
17 /**
18 Forward declares wx wrapper around DirectFB interface @a name.
19
20 Also declares wx##name##Ptr typedef for wxDfbPtr<wx##name> pointer.
21
22 @param name name of the DirectFB interface
23 */
24 #define wxDFB_DECLARE_INTERFACE(name) \
25 class wx##name; \
26 typedef wxDfbPtr<wx##name> wx##name##Ptr;
27
28
29 //-----------------------------------------------------------------------------
30 // wxDfbPtr<T>
31 //-----------------------------------------------------------------------------
32
33 class wxDfbWrapperBase;
34
35 class WXDLLIMPEXP_CORE wxDfbPtrBase
36 {
37 protected:
38 static void DoAddRef(wxDfbWrapperBase *ptr);
39 static void DoRelease(wxDfbWrapperBase *ptr);
40 };
41
42 /**
43 This template implements smart pointer for keeping pointers to DirectFB
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.
47 */
48 template<typename T>
49 class wxDfbPtr : private wxDfbPtrBase
50 {
51 public:
52 /**
53 Creates the pointer from raw pointer to the wrapper.
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 {
70 this->DoRelease((wxDfbWrapperBase*)m_ptr);
71 m_ptr = NULL;
72 }
73 }
74
75 /// Cast to the wrapper pointer
76 operator T*() const { return m_ptr; }
77
78 // standard operators:
79
80 wxDfbPtr& operator=(T *ptr)
81 {
82 Reset();
83 m_ptr = ptr;
84 return *this;
85 }
86
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
97 private:
98 void InitFrom(const wxDfbPtr& ptr)
99 {
100 m_ptr = ptr.m_ptr;
101 if ( m_ptr )
102 this->DoAddRef((wxDfbWrapperBase*)m_ptr);
103 }
104
105 private:
106 T *m_ptr;
107 };
108
109 #endif // _WX_DFB_DFBPTR_H_