2008-03-08 08:52:38 -05:00
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Name: object.h
|
2009-06-12 16:29:59 -04:00
|
|
|
|
// Purpose: interface of wxRefCounter
|
2008-03-08 08:52:38 -05:00
|
|
|
|
// Author: wxWidgets team
|
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
|
// Licence: wxWindows license
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-06-12 16:29:59 -04:00
|
|
|
|
/** @class wxObjectRefData
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2009-06-12 16:29:59 -04:00
|
|
|
|
This class is just a typedef to wxRefCounter and is used by wxObject.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2009-07-30 09:40:46 -04:00
|
|
|
|
Derive classes from this to store your own data in wxObject-derived
|
2009-06-14 10:45:20 -04:00
|
|
|
|
classes. When retrieving information from a wxObject's reference data,
|
|
|
|
|
you will need to cast to your own derived class.
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-06-14 10:45:20 -04:00
|
|
|
|
Below is an example illustrating how to store reference counted
|
|
|
|
|
data in a class derived from wxObject including copy-on-write
|
|
|
|
|
semantics.
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
@section objectrefdata_example Example
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
// include file
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// ------------
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
class MyCar : public wxObject
|
2008-03-30 10:48:22 -04:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MyCar() { }
|
|
|
|
|
MyCar( int price );
|
|
|
|
|
|
|
|
|
|
bool IsOk() const { return m_refData != NULL; }
|
|
|
|
|
|
|
|
|
|
bool operator == ( const MyCar& car ) const;
|
|
|
|
|
bool operator != (const MyCar& car) const { return !(*this == car); }
|
|
|
|
|
|
|
|
|
|
void SetPrice( int price );
|
|
|
|
|
int GetPrice() const;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual wxObjectRefData *CreateRefData() const;
|
|
|
|
|
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
|
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(MyCar)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// implementation
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// --------------
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// the reference data class is typically a private class only visible in the
|
|
|
|
|
// implementation source file of the refcounted class.
|
|
|
|
|
class MyCarRefData : public wxObjectRefData
|
2008-03-30 10:48:22 -04:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MyCarRefData()
|
|
|
|
|
{
|
|
|
|
|
m_price = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyCarRefData( const MyCarRefData& data )
|
|
|
|
|
: wxObjectRefData()
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// copy refcounted data; this is usually a time- and memory-consuming operation
|
|
|
|
|
// and is only done when two (or more) MyCar instances need to unshare a
|
|
|
|
|
// common instance of MyCarRefData
|
2008-03-30 10:48:22 -04:00
|
|
|
|
m_price = data.m_price;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator == (const MyCarRefData& data) const
|
|
|
|
|
{
|
|
|
|
|
return m_price == data.m_price;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
private:
|
|
|
|
|
// in real world, reference counting is usually used only when
|
|
|
|
|
// the wxObjectRefData-derived class holds data very memory-consuming;
|
|
|
|
|
// in this example the various MyCar instances may share a MyCarRefData
|
|
|
|
|
// instance which however only takes 4 bytes for this integer!
|
2008-03-30 10:48:22 -04:00
|
|
|
|
int m_price;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define M_CARDATA ((MyCarRefData *)m_refData)
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(MyCar,wxObject)
|
|
|
|
|
|
|
|
|
|
MyCar::MyCar( int price )
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// here we init the MyCar internal data:
|
2008-03-30 10:48:22 -04:00
|
|
|
|
m_refData = new MyCarRefData();
|
|
|
|
|
M_CARDATA->m_price = price;
|
|
|
|
|
}
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
wxObjectRefData *MyCar::CreateRefData() const
|
|
|
|
|
{
|
|
|
|
|
return new MyCarRefData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxObjectRefData *MyCar::CloneRefData(const wxObjectRefData *data) const
|
|
|
|
|
{
|
|
|
|
|
return new MyCarRefData(*(MyCarRefData *)data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MyCar::operator == ( const MyCar& car ) const
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
if (m_refData == car.m_refData)
|
|
|
|
|
return true;
|
2009-07-30 09:14:25 -04:00
|
|
|
|
if (!m_refData || !car.m_refData)
|
2009-03-14 21:03:48 -04:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// here we use the MyCarRefData::operator==() function.
|
|
|
|
|
// Note however that this comparison may be very slow if the
|
|
|
|
|
// reference data contains a lot of data to be compared.
|
2008-03-30 10:48:22 -04:00
|
|
|
|
return ( *(MyCarRefData*)m_refData == *(MyCarRefData*)car.m_refData );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MyCar::SetPrice( int price )
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// since this function modifies one of the MyCar internal property,
|
|
|
|
|
// we need to be sure that the other MyCar instances which share the
|
|
|
|
|
// same MyCarRefData instance are not affected by this call.
|
|
|
|
|
// I.e. it's very important to call UnShare() in all setters of
|
|
|
|
|
// refcounted classes!
|
2008-03-30 10:48:22 -04:00
|
|
|
|
UnShare();
|
|
|
|
|
|
|
|
|
|
M_CARDATA->m_price = price;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MyCar::GetPrice() const
|
|
|
|
|
{
|
|
|
|
|
wxCHECK_MSG( IsOk(), -1, "invalid car" );
|
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
return M_CARDATA->m_price;
|
2008-03-30 10:48:22 -04:00
|
|
|
|
}
|
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@library{wxbase}
|
|
|
|
|
@category{rtti}
|
|
|
|
|
|
|
|
|
|
@see wxObject, wxObjectDataPtr<T>, @ref overview_refcount
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2009-06-12 16:29:59 -04:00
|
|
|
|
typedef wxRefCounter wxObjectRefData;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@class wxRefCounter
|
|
|
|
|
|
2009-06-14 10:45:20 -04:00
|
|
|
|
This class is used to manage reference-counting providing a simple
|
|
|
|
|
interface and a counter. wxRefCounter can be easily used together
|
|
|
|
|
with wxObjectDataPtr<T> to ensure that no calls to wxRefCounter::DecRef()
|
|
|
|
|
are missed - thus avoiding memory leaks.
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-06-14 10:45:20 -04:00
|
|
|
|
wxObjectRefData is a typedef to wxRefCounter and is used as the
|
2009-07-30 09:14:25 -04:00
|
|
|
|
built-in reference counted storage for wxObject-derived classes.
|
2009-06-12 16:29:59 -04:00
|
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
|
@category{rtti}
|
|
|
|
|
|
|
|
|
|
@see wxObject, wxObjectRefData, wxObjectDataPtr<T>, @ref overview_refcount
|
|
|
|
|
*/
|
|
|
|
|
class wxRefCounter
|
2008-03-08 08:52:38 -05:00
|
|
|
|
{
|
2008-03-30 10:49:43 -04:00
|
|
|
|
protected:
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Destructor.
|
|
|
|
|
|
2009-06-12 16:29:59 -04:00
|
|
|
|
It's declared @c protected so that wxRefCounter instances
|
2008-03-30 10:49:43 -04:00
|
|
|
|
will never be destroyed directly but only as result of a DecRef() call.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2009-06-12 16:29:59 -04:00
|
|
|
|
virtual ~wxRefCounter();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
public:
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Default constructor. Initialises the internal reference count to 1.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2009-06-12 16:29:59 -04:00
|
|
|
|
wxRefCounter();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:48:22 -04:00
|
|
|
|
Decrements the reference count associated with this shared data and, if
|
2009-06-12 16:29:59 -04:00
|
|
|
|
it reaches zero, destroys this instance of wxRefCounter releasing its
|
2008-03-30 10:48:22 -04:00
|
|
|
|
memory.
|
|
|
|
|
|
|
|
|
|
Please note that after calling this function, the caller should
|
|
|
|
|
absolutely avoid to use the pointer to this instance since it may not be
|
|
|
|
|
valid anymore.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
|
|
|
|
void DecRef();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns the reference count associated with this shared data.
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
|
|
|
|
When this goes to zero during a DecRef() call, the object will auto-free itself.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
int GetRefCount() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Increments the reference count associated with this shared data.
|
|
|
|
|
*/
|
|
|
|
|
void IncRef();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
|
|
|
|
@class wxObject
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
This is the root class of many of the wxWidgets classes.
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
It declares a virtual destructor which ensures that destructors get called
|
|
|
|
|
for all derived class objects where necessary.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
wxObject is the hub of a dynamic object creation scheme, enabling a program
|
|
|
|
|
to create instances of a class only knowing its string class name, and to
|
|
|
|
|
query the class hierarchy.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
The class contains optional debugging versions of @b new and @b delete, which
|
|
|
|
|
can help trace memory allocation and deallocation problems.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
wxObject can be used to implement @ref overview_refcount "reference counted"
|
2008-03-30 10:49:43 -04:00
|
|
|
|
objects, such as wxPen, wxBitmap and others
|
|
|
|
|
(see @ref overview_refcount_list "this list").
|
2009-06-12 16:29:59 -04:00
|
|
|
|
See wxRefCounter and @ref overview_refcount for more info about
|
2009-03-14 21:03:48 -04:00
|
|
|
|
reference counting.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
@library{wxbase}
|
|
|
|
|
@category{rtti}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2009-07-30 09:14:25 -04:00
|
|
|
|
@see wxClassInfo, @ref overview_debugging, @ref overview_refcount,
|
2009-06-12 16:29:59 -04:00
|
|
|
|
wxObjectDataRef, wxObjectDataPtr<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
|
class wxObject
|
2008-03-08 08:52:38 -05:00
|
|
|
|
{
|
|
|
|
|
public:
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
/**
|
|
|
|
|
Default ctor; initializes to @NULL the internal reference data.
|
|
|
|
|
*/
|
2008-03-30 10:48:22 -04:00
|
|
|
|
wxObject();
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Copy ctor.
|
2009-03-14 21:03:48 -04:00
|
|
|
|
|
|
|
|
|
Sets the internal wxObject::m_refData pointer to point to the same
|
|
|
|
|
instance of the wxObjectRefData-derived class pointed by @c other and
|
|
|
|
|
increments the refcount of wxObject::m_refData.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
|
wxObject(const wxObject& other);
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Destructor.
|
|
|
|
|
|
|
|
|
|
Performs dereferencing, for those objects that use reference counting.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
|
virtual ~wxObject();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
This virtual function is redefined for every class that requires run-time
|
2008-03-30 10:49:43 -04:00
|
|
|
|
type information, when using the ::DECLARE_CLASS macro (or similar).
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
|
virtual wxClassInfo* GetClassInfo() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@see Ref(), UnRef(), wxObject::m_refData, SetRefData(), wxObjectRefData
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
wxObjectRefData* GetRefData() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Determines whether this class is a subclass of (or the same class as)
|
|
|
|
|
the given class.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
bool tmp = obj->IsKindOf(CLASSINFO(wxFrame));
|
|
|
|
|
@endcode
|
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
|
@param info
|
2008-03-09 08:33:59 -04:00
|
|
|
|
A pointer to a class information object, which may be obtained
|
2008-03-30 10:49:43 -04:00
|
|
|
|
by using the ::CLASSINFO macro.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
|
@return @true if the class represented by info is the same class as this
|
2008-03-09 08:33:59 -04:00
|
|
|
|
one or is derived from it.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-09-22 15:01:17 -04:00
|
|
|
|
bool IsKindOf(const wxClassInfo* info) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Returns @true if this object has the same data pointer as @a obj.
|
|
|
|
|
|
|
|
|
|
Notice that @true is returned if the data pointers are @NULL in both objects.
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
This function only does a @e shallow comparison, i.e. it doesn't compare
|
2008-03-08 08:52:38 -05:00
|
|
|
|
the objects pointed to by the data pointers of these objects.
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
|
|
|
|
@see @ref overview_refcount
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-09-22 15:01:17 -04:00
|
|
|
|
bool IsSameAs(const wxObject& obj) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Makes this object refer to the data in @a clone.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
|
@param clone
|
2008-03-09 08:33:59 -04:00
|
|
|
|
The object to 'clone'.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
@remarks First this function calls UnRef() on itself to decrement
|
2008-03-30 10:49:43 -04:00
|
|
|
|
(and perhaps free) the data it is currently referring to.
|
|
|
|
|
It then sets its own wxObject::m_refData to point to that of @a clone,
|
2008-03-30 10:48:22 -04:00
|
|
|
|
and increments the reference count inside the data.
|
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@see UnRef(), SetRefData(), GetRefData(), wxObjectRefData
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
|
void Ref(const wxObject& clone);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Sets the wxObject::m_refData pointer.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@see Ref(), UnRef(), GetRefData(), wxObjectRefData
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
|
|
|
|
void SetRefData(wxObjectRefData* data);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Decrements the reference count in the associated data, and if it is zero,
|
|
|
|
|
deletes the data.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
The wxObject::m_refData member is set to @NULL.
|
|
|
|
|
|
|
|
|
|
@see Ref(), SetRefData(), GetRefData(), wxObjectRefData
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
|
|
|
|
void UnRef();
|
|
|
|
|
|
|
|
|
|
/**
|
2009-03-14 21:03:48 -04:00
|
|
|
|
This is the same of AllocExclusive() but this method is public.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:48:22 -04:00
|
|
|
|
void UnShare();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
The @e delete operator is defined for debugging versions of the library only,
|
2008-03-30 10:48:22 -04:00
|
|
|
|
when the identifier @c __WXDEBUG__ is defined.
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
It takes over memory deallocation, allowing wxDebugContext operations.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:48:22 -04:00
|
|
|
|
void operator delete(void *buf);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
The @e new operator is defined for debugging versions of the library only, when
|
2008-03-30 10:49:43 -04:00
|
|
|
|
the identifier @c __WXDEBUG__ is defined.
|
|
|
|
|
|
|
|
|
|
It takes over memory allocation, allowing wxDebugContext operations.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:49:43 -04:00
|
|
|
|
void* operator new(size_t size, const wxString& filename = NULL, int lineNum = 0);
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
protected:
|
2009-03-14 21:03:48 -04:00
|
|
|
|
/**
|
|
|
|
|
Ensure that this object's data is not shared with any other object.
|
|
|
|
|
|
|
|
|
|
If we have no data, it is created using CreateRefData();
|
2009-07-30 09:14:25 -04:00
|
|
|
|
if we have shared data (i.e. data with a reference count greater than 1),
|
2009-03-14 21:03:48 -04:00
|
|
|
|
it is copied using CloneRefData(); otherwise nothing is done (the data
|
|
|
|
|
is already present and is not shared by other object instances).
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
If you use this function you should make sure that you override the
|
|
|
|
|
CreateRefData() and CloneRefData() functions in your class otherwise
|
|
|
|
|
an assertion will fail at runtime.
|
|
|
|
|
*/
|
|
|
|
|
void AllocExclusive();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Creates a new instance of the wxObjectRefData-derived class specific to
|
|
|
|
|
this object and returns it.
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
This is usually implemented as a one-line call:
|
|
|
|
|
@code
|
|
|
|
|
wxObjectRefData *MyObject::CreateRefData() const
|
|
|
|
|
{
|
|
|
|
|
return new MyObjectRefData;
|
|
|
|
|
}
|
|
|
|
|
@endcode
|
|
|
|
|
*/
|
|
|
|
|
virtual wxObjectRefData *CreateRefData() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Creates a new instance of the wxObjectRefData-derived class specific to
|
|
|
|
|
this object and initializes it copying @a data.
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
This is usually implemented as a one-line call:
|
|
|
|
|
@code
|
|
|
|
|
wxObjectRefData *MyObject::CloneRefData(const wxObjectRefData *data) const
|
|
|
|
|
{
|
|
|
|
|
// rely on the MyObjectRefData copy ctor:
|
|
|
|
|
return new MyObjectRefData(*(MyObjectRefData *)data);
|
|
|
|
|
}
|
|
|
|
|
@endcode
|
|
|
|
|
*/
|
|
|
|
|
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Pointer to an object which is the object's reference-counted data.
|
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@see Ref(), UnRef(), SetRefData(), GetRefData(), wxObjectRefData
|
2008-03-30 10:48:22 -04:00
|
|
|
|
*/
|
2009-03-14 21:03:48 -04:00
|
|
|
|
wxObjectRefData* m_refData;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
|
|
|
|
@class wxClassInfo
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
This class stores meta-information about classes.
|
|
|
|
|
|
|
|
|
|
Instances of this class are not generally defined directly by an application,
|
|
|
|
|
but indirectly through use of macros such as ::DECLARE_DYNAMIC_CLASS and
|
|
|
|
|
::IMPLEMENT_DYNAMIC_CLASS.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
@library{wxbase}
|
|
|
|
|
@category{rtti}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@see @ref overview_rtti_classinfo, wxObject
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
|
class wxClassInfo
|
2008-03-08 08:52:38 -05:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Constructs a wxClassInfo object.
|
|
|
|
|
|
|
|
|
|
The supplied macros implicitly construct objects of this class, so there is no
|
|
|
|
|
need to create such objects explicitly in an application.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
|
wxClassInfo(const wxChar* className,
|
|
|
|
|
const wxClassInfo* baseClass1,
|
|
|
|
|
const wxClassInfo* baseClass2,
|
2008-03-08 08:52:38 -05:00
|
|
|
|
int size, wxObjectConstructorFn fn);
|
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Creates an object of the appropriate kind.
|
|
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
|
@return @NULL if the class has not been declared dynamically creatable
|
2008-03-30 10:49:43 -04:00
|
|
|
|
(typically, this happens for abstract classes).
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
wxObject* CreateObject() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Finds the wxClassInfo object for a class with the given @a name.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2009-01-10 17:42:09 -05:00
|
|
|
|
static wxClassInfo* FindClass(const wxString& className);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns the name of the first base class (@NULL if none).
|
|
|
|
|
*/
|
2008-10-27 13:12:27 -04:00
|
|
|
|
const wxChar* GetBaseClassName1() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns the name of the second base class (@NULL if none).
|
|
|
|
|
*/
|
2008-10-27 13:12:27 -04:00
|
|
|
|
const wxChar* GetBaseClassName2() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns the string form of the class name.
|
|
|
|
|
*/
|
2008-10-27 13:12:27 -04:00
|
|
|
|
const wxChar* GetClassName() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns the size of the class.
|
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
int GetSize() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns @true if this class info can create objects of the associated class.
|
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
bool IsDynamic() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Returns @true if this class is a kind of (inherits from) the given class.
|
|
|
|
|
*/
|
2008-10-27 17:18:55 -04:00
|
|
|
|
bool IsKindOf(const wxClassInfo* info) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2009-06-14 10:45:20 -04:00
|
|
|
|
This is an helper template class primarily written to avoid memory leaks because
|
|
|
|
|
of missing calls to wxRefCounter::DecRef() and wxObjectRefData::DecRef().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Despite the name this template can actually be used as a smart pointer for any
|
|
|
|
|
class implementing the reference counting interface which only consists of the two
|
|
|
|
|
methods @b T::IncRef() and @b T::DecRef().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
The difference to wxSharedPtr<T> is that wxObjectDataPtr<T> relies on the reference
|
2009-03-14 21:03:48 -04:00
|
|
|
|
counting to be in the class pointed to, where instead wxSharedPtr<T> implements the
|
2008-03-08 08:52:38 -05:00
|
|
|
|
reference counting itself.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2009-06-14 10:45:20 -04:00
|
|
|
|
Below is an example illustrating how to implement reference counted
|
|
|
|
|
data using wxRefCounter and wxObjectDataPtr<T> with copy-on-write
|
|
|
|
|
semantics.
|
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
@section objectdataptr_example Example
|
2008-03-30 10:48:22 -04:00
|
|
|
|
|
|
|
|
|
@code
|
2009-06-14 10:45:20 -04:00
|
|
|
|
class MyCarRefData: public wxRefCounter
|
2008-03-30 10:48:22 -04:00
|
|
|
|
{
|
|
|
|
|
public:
|
2009-06-14 10:45:20 -04:00
|
|
|
|
MyCarRefData( int price = 0 ) : m_price(price) { }
|
|
|
|
|
MyCarRefData( const MyCarRefData& data ) : m_price(data.m_price) { }
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
void SetPrice( int price ) { m_price = price; }
|
2009-03-14 21:03:48 -04:00
|
|
|
|
int GetPrice() const { return m_price; }
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2008-03-30 10:48:22 -04:00
|
|
|
|
protected:
|
|
|
|
|
int m_price;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MyCar
|
|
|
|
|
{
|
|
|
|
|
public:
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// initializes this MyCar assigning to the
|
|
|
|
|
// internal data pointer a new instance of MyCarRefData
|
2009-06-14 10:45:20 -04:00
|
|
|
|
MyCar( int price = 0 ) : m_data( new MyCarRefData(price) )
|
2008-03-30 10:48:22 -04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyCar& operator =( const MyCar& tocopy )
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// shallow copy: this is just a fast copy of pointers; the real
|
|
|
|
|
// memory-consuming data which typically is stored inside
|
|
|
|
|
// MyCarRefData is not copied here!
|
2008-03-30 10:48:22 -04:00
|
|
|
|
m_data = tocopy.m_data;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator == ( const MyCar& other ) const
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
if (m_data.get() == other.m_data.get())
|
|
|
|
|
return true; // this instance and the 'other' one share the
|
|
|
|
|
// same MyCarRefData data...
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-06-14 10:45:20 -04:00
|
|
|
|
return (m_data.GetPrice() == other.m_data.GetPrice());
|
2008-03-30 10:48:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetPrice( int price )
|
|
|
|
|
{
|
2009-03-14 21:03:48 -04:00
|
|
|
|
// make sure changes to this class do not affect other instances
|
|
|
|
|
// currently sharing our same refcounted data:
|
|
|
|
|
UnShare();
|
2009-07-30 09:14:25 -04:00
|
|
|
|
|
2009-03-14 21:03:48 -04:00
|
|
|
|
m_data->SetPrice( price );
|
2008-03-30 10:48:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GetPrice() const
|
|
|
|
|
{
|
|
|
|
|
return m_data->GetPrice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxObjectDataPtr<MyCarRefData> m_data;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void UnShare()
|
|
|
|
|
{
|
|
|
|
|
if (m_data->GetRefCount() == 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_data.reset( new MyCarRefData( *m_data ) );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
|
|
|
|
@library{wxbase}
|
|
|
|
|
@category{rtti,smartpointers}
|
|
|
|
|
|
|
|
|
|
@see wxObject, wxObjectRefData, @ref overview_refcount, wxSharedPtr<T>,
|
|
|
|
|
wxScopedPtr<T>, wxWeakRef<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2009-03-14 21:03:48 -04:00
|
|
|
|
template <class T>
|
2008-03-08 09:43:31 -05:00
|
|
|
|
class wxObjectDataPtr<T>
|
2008-03-08 08:52:38 -05:00
|
|
|
|
{
|
|
|
|
|
public:
|
2008-03-30 10:48:22 -04:00
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Constructor.
|
|
|
|
|
|
|
|
|
|
@a ptr is a pointer to the reference counted object to which this class points.
|
2008-03-30 10:48:22 -04:00
|
|
|
|
If @a ptr is not NULL @b T::IncRef() will be called on the object.
|
|
|
|
|
*/
|
|
|
|
|
wxObjectDataPtr<T>(T* ptr = NULL);
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
This copy constructor increases the count of the reference counted object to
|
|
|
|
|
which @a tocopy points and then this class will point to, as well.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:48:22 -04:00
|
|
|
|
wxObjectDataPtr<T>(const wxObjectDataPtr<T>& tocopy);
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Decreases the reference count of the object to which this class points.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:49:43 -04:00
|
|
|
|
~wxObjectDataPtr<T>();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Gets a pointer to the reference counted object to which this class points.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
T* get() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
/**
|
|
|
|
|
Reset this class to ptr which points to a reference counted object and
|
|
|
|
|
calls T::DecRef() on the previously owned object.
|
|
|
|
|
*/
|
2008-05-15 07:53:06 -04:00
|
|
|
|
void reset(T *ptr);
|
2008-03-30 10:49:43 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-08 09:43:31 -05:00
|
|
|
|
Conversion to a boolean expression (in a variant which is not
|
2008-03-30 10:49:43 -04:00
|
|
|
|
convertable to anything but a boolean expression).
|
|
|
|
|
|
|
|
|
|
If this class contains a valid pointer it will return @true, if it contains
|
|
|
|
|
a @NULL pointer it will return @false.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
|
operator unspecified_bool_type() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Returns a reference to the object.
|
|
|
|
|
|
|
|
|
|
If the internal pointer is @NULL this method will cause an assert in debug mode.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:48:22 -04:00
|
|
|
|
T& operator*() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Returns a pointer to the reference counted object to which this class points.
|
|
|
|
|
|
|
|
|
|
If this the internal pointer is @NULL, this method will assert in debug mode.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:49:43 -04:00
|
|
|
|
T* operator->() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
//@{
|
|
|
|
|
/**
|
2008-03-30 10:49:43 -04:00
|
|
|
|
Assignment operator.
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-30 10:48:22 -04:00
|
|
|
|
wxObjectDataPtr<T>& operator=(const wxObjectDataPtr<T>& tocopy);
|
|
|
|
|
wxObjectDataPtr<T>& operator=(T* ptr);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
//@}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
// ============================================================================
|
|
|
|
|
// Global functions/macros
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
2009-01-05 15:48:06 -05:00
|
|
|
|
/** @addtogroup group_funcmacro_rtti */
|
2008-03-14 03:44:48 -04:00
|
|
|
|
//@{
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Returns a pointer to the wxClassInfo object associated with this class.
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
*/
|
|
|
|
|
#define CLASSINFO( className )
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Used inside a class declaration to declare that the class should be made
|
|
|
|
|
known to the class hierarchy, but objects of this class cannot be created
|
|
|
|
|
dynamically. The same as DECLARE_ABSTRACT_CLASS().
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define DECLARE_CLASS( className )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Used inside a class declaration to declare that the class should be
|
|
|
|
|
made known to the class hierarchy, but objects of this class cannot be created
|
2008-03-14 03:44:48 -04:00
|
|
|
|
dynamically. The same as DECLARE_CLASS().
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
Example:
|
2008-03-09 08:33:59 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
@code
|
|
|
|
|
class wxCommand: public wxObject
|
|
|
|
|
{
|
2008-03-14 03:44:48 -04:00
|
|
|
|
DECLARE_ABSTRACT_CLASS(wxCommand)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
private:
|
|
|
|
|
...
|
|
|
|
|
public:
|
|
|
|
|
...
|
2008-03-08 08:52:38 -05:00
|
|
|
|
};
|
|
|
|
|
@endcode
|
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define DECLARE_ABSTRACT_CLASS( className )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used inside a class declaration to make the class known to wxWidgets RTTI
|
|
|
|
|
system and also declare that the objects of this class should be
|
|
|
|
|
dynamically creatable from run-time type information. Notice that this
|
|
|
|
|
implies that the class should have a default constructor, if this is not
|
|
|
|
|
the case consider using DECLARE_CLASS().
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/object.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
class wxFrame: public wxWindow
|
|
|
|
|
{
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxFrame)
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const wxString& frameTitle;
|
|
|
|
|
public:
|
|
|
|
|
...
|
|
|
|
|
};
|
|
|
|
|
@endcode
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 04:05:31 -04:00
|
|
|
|
#define DECLARE_DYNAMIC_CLASS( className )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used in a C++ implementation file to complete the declaration of a class
|
|
|
|
|
that has run-time type information. The same as IMPLEMENT_ABSTRACT_CLASS().
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define IMPLEMENT_CLASS( className, baseClassName )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used in a C++ implementation file to complete the declaration of a class
|
|
|
|
|
that has run-time type information and two base classes. The same as
|
|
|
|
|
IMPLEMENT_ABSTRACT_CLASS2().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/object.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define IMPLEMENT_CLASS2( className, baseClassName1, baseClassName2 )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used in a C++ implementation file to complete the declaration of a class
|
|
|
|
|
that has run-time type information. The same as IMPLEMENT_CLASS().
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
Example:
|
2008-03-09 08:33:59 -04:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
@code
|
|
|
|
|
IMPLEMENT_ABSTRACT_CLASS(wxCommand, wxObject)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
|
wxCommand::wxCommand(void)
|
|
|
|
|
{
|
2008-03-14 03:44:48 -04:00
|
|
|
|
...
|
2008-03-08 08:52:38 -05:00
|
|
|
|
}
|
|
|
|
|
@endcode
|
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define IMPLEMENT_ABSTRACT_CLASS( className, baseClassName )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used in a C++ implementation file to complete the declaration of a class
|
|
|
|
|
that has run-time type information and two base classes. The same as
|
|
|
|
|
IMPLEMENT_CLASS2().
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define IMPLEMENT_ABSTRACT_CLASS2( className, baseClassName1, baseClassName2 )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used in a C++ implementation file to complete the declaration of a class
|
|
|
|
|
that has run-time type information, and whose instances can be created
|
|
|
|
|
dynamically.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
|
|
|
|
|
|
|
|
|
|
wxFrame::wxFrame(void)
|
|
|
|
|
{
|
|
|
|
|
...
|
|
|
|
|
}
|
|
|
|
|
@endcode
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define IMPLEMENT_DYNAMIC_CLASS( className, baseClassName )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
Used in a C++ implementation file to complete the declaration of a class
|
|
|
|
|
that has run-time type information, and whose instances can be created
|
|
|
|
|
dynamically. Use this for classes derived from two base classes.
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define IMPLEMENT_DYNAMIC_CLASS2( className, baseClassName1, baseClassName2 )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:48:22 -04:00
|
|
|
|
Same as @c const_cast<T>(x) if the compiler supports const cast or @c (T)x for
|
|
|
|
|
old compilers. Unlike wxConstCast(), the cast it to the type @c T and not to
|
|
|
|
|
<tt>T *</tt> and also the order of arguments is the same as for the standard cast.
|
2008-03-14 03:44:48 -04:00
|
|
|
|
|
|
|
|
|
@header{wx/defs.h}
|
|
|
|
|
|
|
|
|
|
@see wx_reinterpret_cast(), wx_static_cast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define wx_const_cast(T, x)
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:48:22 -04:00
|
|
|
|
Same as @c reinterpret_cast<T>(x) if the compiler supports reinterpret cast or
|
|
|
|
|
@c (T)x for old compilers.
|
2008-03-09 08:33:59 -04:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/defs.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@see wx_const_cast(), wx_static_cast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define wx_reinterpret_cast(T, x)
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:48:22 -04:00
|
|
|
|
Same as @c static_cast<T>(x) if the compiler supports static cast or @c (T)x for
|
2008-03-14 03:44:48 -04:00
|
|
|
|
old compilers. Unlike wxStaticCast(), there are no checks being done and
|
|
|
|
|
the meaning of the macro arguments is exactly the same as for the standard
|
2008-03-30 10:48:22 -04:00
|
|
|
|
static cast, i.e. @a T is the full type name and star is not appended to it.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/defs.h}
|
|
|
|
|
|
|
|
|
|
@see wx_const_cast(), wx_reinterpret_cast(), wx_truncate_cast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define wx_static_cast(T, x)
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
This case doesn’t correspond to any standard cast but exists solely to make
|
|
|
|
|
casts which possibly result in a truncation of an integer value more
|
|
|
|
|
readable.
|
|
|
|
|
|
|
|
|
|
@header{wx/defs.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 03:44:48 -04:00
|
|
|
|
#define wx_truncate_cast(T, x)
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:48:22 -04:00
|
|
|
|
This macro expands into <tt>const_cast<classname *>(ptr)</tt> if the compiler
|
2008-03-14 03:44:48 -04:00
|
|
|
|
supports const_cast or into an old, C-style cast, otherwise.
|
2008-03-09 08:33:59 -04:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/defs.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@see wx_const_cast(), wxDynamicCast(), wxStaticCast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 04:05:31 -04:00
|
|
|
|
#define wxConstCast( ptr, classname )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
This macro returns the pointer @e ptr cast to the type @e classname * if
|
|
|
|
|
the pointer is of this type (the check is done during the run-time) or
|
|
|
|
|
@NULL otherwise. Usage of this macro is preferred over obsoleted
|
|
|
|
|
wxObject::IsKindOf() function.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
The @e ptr argument may be @NULL, in which case @NULL will be returned.
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
wxWindow *win = wxWindow::FindFocus();
|
|
|
|
|
wxTextCtrl *text = wxDynamicCast(win, wxTextCtrl);
|
|
|
|
|
if ( text )
|
|
|
|
|
{
|
|
|
|
|
// a text control has the focus...
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// no window has the focus or it is not a text control
|
|
|
|
|
}
|
|
|
|
|
@endcode
|
|
|
|
|
|
2008-03-30 10:49:43 -04:00
|
|
|
|
@see @ref overview_rtti, wxDynamicCastThis(), wxConstCast(), wxStaticCast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 04:05:31 -04:00
|
|
|
|
#define wxDynamicCast( ptr, classname )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-30 10:48:22 -04:00
|
|
|
|
This macro is equivalent to <tt>wxDynamicCast(this, classname)</tt> but the latter provokes
|
2008-03-14 03:44:48 -04:00
|
|
|
|
spurious compilation warnings from some compilers (because it tests whether
|
|
|
|
|
@c this pointer is non-@NULL which is always true), so this macro should be
|
|
|
|
|
used to avoid them.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
|
|
|
|
|
@see wxDynamicCast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 04:05:31 -04:00
|
|
|
|
#define wxDynamicCastThis( classname )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2008-03-14 03:44:48 -04:00
|
|
|
|
This macro checks that the cast is valid in debug mode (an assert failure
|
|
|
|
|
will result if wxDynamicCast(ptr, classname) == @NULL) and then returns the
|
2008-03-30 10:48:22 -04:00
|
|
|
|
result of executing an equivalent of <tt>static_cast<classname *>(ptr)</tt>.
|
2008-03-09 08:33:59 -04:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@header{wx/object.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
|
2008-03-14 03:44:48 -04:00
|
|
|
|
@see wx_static_cast(), wxDynamicCast(), wxConstCast()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
*/
|
2008-03-14 04:05:31 -04:00
|
|
|
|
#define wxStaticCast( ptr, classname )
|
2008-03-14 03:44:48 -04:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Creates and returns an object of the given class, if the class has been
|
|
|
|
|
registered with the dynamic class system using DECLARE... and IMPLEMENT...
|
|
|
|
|
macros.
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
*/
|
2008-03-14 04:05:31 -04:00
|
|
|
|
wxObject *wxCreateDynamicObject(const wxString& className);
|
2008-03-14 03:44:48 -04:00
|
|
|
|
|
|
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
2009-01-05 15:48:06 -05:00
|
|
|
|
/** @addtogroup group_funcmacro_debug */
|
2008-04-02 01:29:12 -04:00
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
This is defined in debug mode to be call the redefined new operator
|
|
|
|
|
with filename and line number arguments. The definition is:
|
|
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
#define WXDEBUG_NEW new(__FILE__,__LINE__)
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
|
|
In non-debug mode, this is defined as the normal new operator.
|
|
|
|
|
|
|
|
|
|
@header{wx/object.h}
|
|
|
|
|
*/
|
|
|
|
|
#define WXDEBUG_NEW( arg )
|
|
|
|
|
|
|
|
|
|
//@}
|
|
|
|
|
|