1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dfb/dfbptr.h
3 // Purpose: wxDfbPtr<T> for holding objects declared in wrapdfb.h
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2006 REA Elektronik GmbH
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_DFB_DFBPTR_H_
11 #define _WX_DFB_DFBPTR_H_
13 //-----------------------------------------------------------------------------
14 // wxDFB_DECLARE_INTERFACE
15 //-----------------------------------------------------------------------------
18 Forward declares wx wrapper around DirectFB interface @a name.
20 Also declares wx##name##Ptr typedef for wxDfbPtr<wx##name> pointer.
22 @param name name of the DirectFB interface
24 #define wxDFB_DECLARE_INTERFACE(name) \
26 typedef wxDfbPtr<wx##name> wx##name##Ptr;
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 class wxDfbWrapperBase
;
35 class WXDLLIMPEXP_CORE wxDfbPtrBase
38 static void DoAddRef(wxDfbWrapperBase
*ptr
);
39 static void DoRelease(wxDfbWrapperBase
*ptr
);
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.
49 class wxDfbPtr
: private wxDfbPtrBase
53 Creates the pointer from raw pointer to the wrapper.
55 Takes ownership of @a ptr, i.e. AddRef() is @em not called on it.
57 wxDfbPtr(T
*ptr
= NULL
) : m_ptr(ptr
) {}
60 wxDfbPtr(const wxDfbPtr
& ptr
) { InitFrom(ptr
); }
62 /// Dtor. Releases the interface
63 ~wxDfbPtr() { Reset(); }
65 /// Resets the pointer to NULL, decreasing reference count of the interface.
70 this->DoRelease((wxDfbWrapperBase
*)m_ptr
);
75 /// Cast to the wrapper pointer
76 operator T
*() const { return m_ptr
; }
78 // standard operators:
80 wxDfbPtr
& operator=(T
*ptr
)
87 wxDfbPtr
& operator=(const wxDfbPtr
& ptr
)
94 T
& operator*() const { return *m_ptr
; }
95 T
* operator->() const { return m_ptr
; }
98 void InitFrom(const wxDfbPtr
& ptr
)
102 this->DoAddRef((wxDfbWrapperBase
*)m_ptr
);
109 #endif // _WX_DFB_DFBPTR_H_