Version: 3.1.1

#include <wx/object.h>

Inherited by wxAcceleratorTable, wxAccessible, wxAnimation, wxArchiveClassFactory, wxArchiveEntry, wxArtProvider, wxAutomationObject, wxBitmapHandler, wxClient, wxClipboard, wxColour, wxColourData, wxCommand, wxCommandProcessor, wxConfigBase, wxConnection, wxConnectionBase, wxContextHelp, wxDataViewIconText, wxDataViewRenderer, wxDC, wxDDEClient, wxDocTemplate, wxDragImage, wxEncodingConverter, wxEvent, wxEvtHandler, wxFileHistory, wxFileSystem, wxFileSystemHandler, wxFilterClassFactory, wxFindReplaceData, wxFontData, wxFSFile, wxGDIObject, wxGLContext, wxGraphicsObject, wxGraphicsRenderer, wxGridTableBase, wxHashTable, wxHelpControllerBase, wxHtmlCell, wxHtmlDCRenderer, wxHtmlEasyPrinting, wxHtmlFilter, wxHtmlHelpData, wxHtmlLinkInfo, wxHtmlTagHandler, wxImage, wxImageHandler, wxImageList, wxIndividualLayoutConstraint, wxJoystick, wxLayoutAlgorithm, wxLayoutConstraints, wxListItem, wxMask, wxMenuItem, wxMetafile, wxModule, wxPageSetupDialog, wxPageSetupDialogData, wxPGCell, wxPGEditor, wxPGEditorDialogAdapter, wxPGProperty, wxPrintData, wxPrintDialog, wxPrintDialogData, wxPrinter, wxPrintout, wxPrintPreview, wxQuantize, wxRegionIterator, wxRichTextAction, wxRichTextDrawingContext, wxRichTextDrawingHandler, wxRichTextFieldType, wxRichTextFileHandler, wxRichTextFontTable, wxRichTextFormattingDialogFactory, wxRichTextHeaderFooterData, wxRichTextImageBlock, wxRichTextObject, wxRichTextPrinting, wxRichTextProperties, wxRichTextRenderer, wxRichTextStyleDefinition, wxRichTextStyleSheet, wxSizer, wxSizerItem, wxSockAddress, wxSocketBase, wxSound, wxStringTokenizer, wxSystemOptions, wxSystemSettings, wxTCPClient, wxTCPConnection, wxTCPServer, wxToolBarToolBase, wxToolTip, wxURI, wxVariant, wxWebViewFactory, wxXmlDocument, wxXmlResource, and wxXmlResourceHandler.

Detailed Description

This is the root class of many of the wxWidgets classes.

It declares a virtual destructor which ensures that destructors get called for all derived class objects where necessary.

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.

The class contains optional debugging versions of new and delete, which can help trace memory allocation and deallocation problems.

wxObject can be used to implement reference counted objects, such as wxPen, wxBitmap and others (see this list). See wxRefCounter and Reference Counting for more info about reference counting.

Library:  wxBase
Category:  Runtime Type Information (RTTI)
See also
wxClassInfo, Debugging, Reference Counting, wxObjectDataRef, wxObjectDataPtr<T>

Public Member Functions

 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More...
 

Protected Member Functions

void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 

Protected Attributes

wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

wxObject::wxObject ( )

Default ctor; initializes to NULL the internal reference data.

wxObject::wxObject ( const wxObject other)

Copy ctor.

Sets the internal wxObject::m_refData pointer to point to the same instance of the wxObjectRefData-derived class pointed by other and increments the refcount of wxObject::m_refData.

virtual wxObject::~wxObject ( )
virtual

Destructor.

Performs dereferencing, for those objects that use reference counting.

Member Function Documentation

void wxObject::AllocExclusive ( )
protected

Ensure that this object's data is not shared with any other object.

If we have no data, it is created using CreateRefData(); if we have shared data (i.e. data with a reference count greater than 1), it is copied using CloneRefData(); otherwise nothing is done (the data is already present and is not shared by other object instances).

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.

virtual wxObjectRefData* wxObject::CloneRefData ( const wxObjectRefData data) const
protectedvirtual

Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data.

This is usually implemented as a one-line call:

wxObjectRefData *MyObject::CloneRefData(const wxObjectRefData *data) const
{
// rely on the MyObjectRefData copy ctor:
return new MyObjectRefData(*(MyObjectRefData *)data);
}
virtual wxObjectRefData* wxObject::CreateRefData ( ) const
protectedvirtual

Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it.

This is usually implemented as a one-line call:

wxObjectRefData *MyObject::CreateRefData() const
{
return new MyObjectRefData;
}
virtual wxClassInfo* wxObject::GetClassInfo ( ) const
virtual

This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).

wxObjectRefData* wxObject::GetRefData ( ) const

Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.

See also
Ref(), UnRef(), wxObject::m_refData, SetRefData(), wxObjectRefData
bool wxObject::IsKindOf ( const wxClassInfo info) const

Determines whether this class is a subclass of (or the same class as) the given class.

Example:

bool tmp = obj->IsKindOf(wxCLASSINFO(wxFrame));
Parameters
infoA pointer to a class information object, which may be obtained by using the wxCLASSINFO macro.
Returns
true if the class represented by info is the same class as this one or is derived from it.
bool wxObject::IsSameAs ( const wxObject obj) const

Returns true if this object has the same data pointer as obj.

Notice that true is returned if the data pointers are NULL in both objects.

This function only does a shallow comparison, i.e. it doesn't compare the objects pointed to by the data pointers of these objects.

See also
Reference Counting
void wxObject::operator delete ( void *  buf)

The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.

It takes over memory deallocation, allowing wxDebugContext operations.

void* wxObject::operator new ( size_t  size,
const wxString filename = NULL,
int  lineNum = 0 
)

The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.

It takes over memory allocation, allowing wxDebugContext operations.

void wxObject::Ref ( const wxObject clone)

Makes this object refer to the data in clone.

Parameters
cloneThe object to 'clone'.
Remarks
First this function calls UnRef() on itself to decrement (and perhaps free) the data it is currently referring to. It then sets its own wxObject::m_refData to point to that of clone, and increments the reference count inside the data.
See also
UnRef(), SetRefData(), GetRefData(), wxObjectRefData
void wxObject::SetRefData ( wxObjectRefData data)
void wxObject::UnRef ( )

Decrements the reference count in the associated data, and if it is zero, deletes the data.

The wxObject::m_refData member is set to NULL.

See also
Ref(), SetRefData(), GetRefData(), wxObjectRefData
void wxObject::UnShare ( )

This is the same of AllocExclusive() but this method is public.

Member Data Documentation

wxObjectRefData* wxObject::m_refData
protected

Pointer to an object which is the object's reference-counted data.

See also
Ref(), UnRef(), SetRefData(), GetRefData(), wxObjectRefData