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