Derive classes from this to store your own data in wxObject-derived classes. When retrieving information from a wxObject's reference data, you will need to cast to your own derived class.
Below is an example illustrating how to store reference counted data in a class derived from wxObject including copy-on-write semantics.
{
public:
MyCar() { }
MyCar( int price );
bool IsOk() const { return m_refData != NULL; }
bool operator != (
const MyCar& car)
const {
return !(*
this == car); }
void SetPrice( int price );
int GetPrice() const;
protected:
};
{
public:
MyCarRefData()
{
m_price = 0;
}
MyCarRefData( const MyCarRefData& data )
{
m_price = data.m_price;
}
{
return m_price == data.m_price;
}
private:
int m_price;
};
#define M_CARDATA ((MyCarRefData *)m_refData)
MyCar::MyCar( int price )
{
m_refData = new MyCarRefData();
M_CARDATA->m_price = price;
}
{
return new MyCarRefData;
}
{
return new MyCarRefData(*(MyCarRefData *)data);
}
{
if (m_refData == car.m_refData)
return true;
if (!m_refData || !car.m_refData)
return false;
return ( *(MyCarRefData*)m_refData == *(MyCarRefData*)car.m_refData );
}
void MyCar::SetPrice( int price )
{
UnShare();
M_CARDATA->m_price = price;
}
int MyCar::GetPrice() const
{
return M_CARDATA->m_price;
}
This is the root class of many of the wxWidgets classes.
Definition: object.h:233
This class is just a typedef to wxRefCounter and is used by wxObject.
#define wxCHECK_MSG(condition, retValue, message)
Checks that the condition is true, returns with the given return value if not (stops execution in deb...
Definition: debug.h:180
#define wxIMPLEMENT_DYNAMIC_CLASS(className, baseClassName)
Used in a C++ implementation file to complete the declaration of a class that has run-time type infor...
Definition: object.h:788
#define wxDECLARE_DYNAMIC_CLASS(className)
Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare tha...
Definition: object.h:730
bool operator!=(const wxString &s1, const wxString &s2)
Comparison operator for string types.
bool operator==(const wxString &s1, const wxString &s2)
Comparison operator for string types.