2006-08-27 05:42:42 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-09-06 05:40:31 -04:00
|
|
|
// Name: wx/dfb/dfbptr.h
|
|
|
|
// Purpose: wxDfbPtr<T> for holding objects declared in wrapdfb.h
|
2006-08-27 05:42:42 -04:00
|
|
|
// Author: Vaclav Slavik
|
|
|
|
// Created: 2006-08-09
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2006 REA Elektronik GmbH
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
#ifndef _WX_DFB_DFBPTR_H_
|
|
|
|
#define _WX_DFB_DFBPTR_H_
|
2006-08-27 05:42:42 -04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxDFB_DECLARE_INTERFACE
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2006-09-06 05:40:31 -04:00
|
|
|
Forward declares wx wrapper around DirectFB interface @a name.
|
2006-08-27 05:42:42 -04:00
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
Also declares wx##name##Ptr typedef for wxDfbPtr<wx##name> pointer.
|
2006-08-27 05:42:42 -04:00
|
|
|
|
|
|
|
@param name name of the DirectFB interface
|
|
|
|
*/
|
|
|
|
#define wxDFB_DECLARE_INTERFACE(name) \
|
2006-09-06 05:40:31 -04:00
|
|
|
class wx##name; \
|
|
|
|
typedef wxDfbPtr<wx##name> wx##name##Ptr;
|
2006-08-27 05:42:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2006-09-06 05:40:31 -04:00
|
|
|
// wxDfbPtr<T>
|
2006-08-27 05:42:42 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
class wxDfbWrapperBase;
|
|
|
|
|
2007-07-05 13:59:27 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxDfbPtrBase
|
2006-08-27 05:42:42 -04:00
|
|
|
{
|
|
|
|
protected:
|
2006-09-06 05:40:31 -04:00
|
|
|
static void DoAddRef(wxDfbWrapperBase *ptr);
|
|
|
|
static void DoRelease(wxDfbWrapperBase *ptr);
|
2006-08-27 05:42:42 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This template implements smart pointer for keeping pointers to DirectFB
|
2006-09-06 05:40:31 -04:00
|
|
|
wrappers (i.e. wxIFoo classes derived from wxDfbWrapper<T>). Interface's
|
|
|
|
reference count is increased on copying and the interface is released when
|
|
|
|
the pointer is deleted.
|
2006-08-27 05:42:42 -04:00
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
class wxDfbPtr : private wxDfbPtrBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2006-09-06 05:40:31 -04:00
|
|
|
Creates the pointer from raw pointer to the wrapper.
|
2006-08-27 05:42:42 -04:00
|
|
|
|
|
|
|
Takes ownership of @a ptr, i.e. AddRef() is @em not called on it.
|
|
|
|
*/
|
|
|
|
wxDfbPtr(T *ptr = NULL) : m_ptr(ptr) {}
|
|
|
|
|
|
|
|
/// Copy ctor
|
|
|
|
wxDfbPtr(const wxDfbPtr& ptr) { InitFrom(ptr); }
|
|
|
|
|
|
|
|
/// Dtor. Releases the interface
|
|
|
|
~wxDfbPtr() { Reset(); }
|
|
|
|
|
|
|
|
/// Resets the pointer to NULL, decreasing reference count of the interface.
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
if ( m_ptr )
|
|
|
|
{
|
2006-09-06 05:40:31 -04:00
|
|
|
this->DoRelease((wxDfbWrapperBase*)m_ptr);
|
2006-08-27 05:42:42 -04:00
|
|
|
m_ptr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
/// Cast to the wrapper pointer
|
2006-08-27 05:42:42 -04:00
|
|
|
operator T*() const { return m_ptr; }
|
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
// standard operators:
|
2006-08-27 05:42:42 -04:00
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
wxDfbPtr& operator=(T *ptr)
|
2006-08-27 05:42:42 -04:00
|
|
|
{
|
|
|
|
Reset();
|
2006-09-06 05:40:31 -04:00
|
|
|
m_ptr = ptr;
|
|
|
|
return *this;
|
2006-08-27 05:42:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
wxDfbPtr& operator=(const wxDfbPtr& ptr)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
InitFrom(ptr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
T& operator*() const { return *m_ptr; }
|
|
|
|
T* operator->() const { return m_ptr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void InitFrom(const wxDfbPtr& ptr)
|
|
|
|
{
|
|
|
|
m_ptr = ptr.m_ptr;
|
|
|
|
if ( m_ptr )
|
2006-09-06 05:40:31 -04:00
|
|
|
this->DoAddRef((wxDfbWrapperBase*)m_ptr);
|
2006-08-27 05:42:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T *m_ptr;
|
|
|
|
};
|
|
|
|
|
2006-09-06 05:40:31 -04:00
|
|
|
#endif // _WX_DFB_DFBPTR_H_
|