]>
git.saurik.com Git - wxWidgets.git/blob - 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 
   7 // Copyright:   (c) 2006 REA Elektronik GmbH 
   8 // Licence:     wxWindows licence 
   9 ///////////////////////////////////////////////////////////////////////////// 
  11 #ifndef _WX_DFB_DFBPTR_H_ 
  12 #define _WX_DFB_DFBPTR_H_ 
  14 //----------------------------------------------------------------------------- 
  15 // wxDFB_DECLARE_INTERFACE 
  16 //----------------------------------------------------------------------------- 
  19     Forward declares wx wrapper around DirectFB interface @a name. 
  21     Also declares wx##name##Ptr typedef for wxDfbPtr<wx##name> pointer. 
  23     @param name  name of the DirectFB interface 
  25 #define wxDFB_DECLARE_INTERFACE(name)            \ 
  27     typedef wxDfbPtr<wx##name> wx##name##Ptr; 
  30 //----------------------------------------------------------------------------- 
  32 //----------------------------------------------------------------------------- 
  34 class wxDfbWrapperBase
; 
  39     static void DoAddRef(wxDfbWrapperBase 
*ptr
); 
  40     static void DoRelease(wxDfbWrapperBase 
*ptr
); 
  44     This template implements smart pointer for keeping pointers to DirectFB 
  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. 
  50 class wxDfbPtr 
: private wxDfbPtrBase
 
  54         Creates the pointer from raw pointer to the wrapper. 
  56         Takes ownership of @a ptr, i.e. AddRef() is @em not called on it. 
  58     wxDfbPtr(T 
*ptr 
= NULL
) : m_ptr(ptr
) {} 
  61     wxDfbPtr(const wxDfbPtr
& ptr
) { InitFrom(ptr
); } 
  63     /// Dtor. Releases the interface 
  64     ~wxDfbPtr() { Reset(); } 
  66     /// Resets the pointer to NULL, decreasing reference count of the interface. 
  71             this->DoRelease((wxDfbWrapperBase
*)m_ptr
); 
  76     /// Cast to the wrapper pointer 
  77     operator T
*() const { return m_ptr
; } 
  79     // standard operators: 
  81     wxDfbPtr
& operator=(T 
*ptr
) 
  88     wxDfbPtr
& operator=(const wxDfbPtr
& ptr
) 
  95     T
& operator*() const { return *m_ptr
; } 
  96     T
* operator->() const { return m_ptr
; } 
  99     void InitFrom(const wxDfbPtr
& ptr
) 
 103             this->DoAddRef((wxDfbWrapperBase
*)m_ptr
); 
 110 #endif // _WX_DFB_DFBPTR_H_