@section overview_refcount_object Making Your Own Reference Counted Class
-Reference counting can be implemented easily using wxObject and wxObjectRefData
-classes. Alternatively, you can also use the wxObjectDataPtr<T> template.
+Reference counting can be implemented easily using wxObject or using
+the intermediate wxRefCounter class directly.
+Alternatively, you can also use the wxObjectDataPtr<T> template.
-First, derive a new class from wxObjectRefData and put there the
-memory-consuming data.
+First, derive a new class from wxRefCounter (or wxObjectRefData when
+using a wxObject derived class) and put the memory-consuming data in it.
Then derive a new class from wxObject and implement there the public interface
which will be seen by the user of your class. You'll probably want to add a
/////////////////////////////////////////////////////////////////////////////
// Name: object.h
-// Purpose: interface of wxObjectRefData
+// Purpose: interface of wxRefCounter
// Author: wxWidgets team
// RCS-ID: $Id$
// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
-/**
- @class wxObjectRefData
+/** @class wxObjectRefData
- This class is used to store reference-counted data.
+ This class is just a typedef to wxRefCounter and is used by wxObject.
Derive classes from this to store your own data. When retrieving information
from a wxObject's reference data, you will need to cast to your own derived class.
}
@endcode
-
+
@library{wxbase}
@category{rtti}
@see wxObject, wxObjectDataPtr<T>, @ref overview_refcount
*/
-class wxObjectRefData
+typedef wxRefCounter wxObjectRefData;
+
+
+/**
+ @class wxRefCounter
+
+ This class is used to manage reference-counting.
+
+ @library{wxbase}
+ @category{rtti}
+
+ @see wxObject, wxObjectRefData, wxObjectDataPtr<T>, @ref overview_refcount
+*/
+class wxRefCounter
{
protected:
/**
Destructor.
- It's declared @c protected so that wxObjectRefData instances
+ It's declared @c protected so that wxRefCounter instances
will never be destroyed directly but only as result of a DecRef() call.
*/
- virtual ~wxObjectRefData();
+ virtual ~wxRefCounter();
public:
/**
Default constructor. Initialises the internal reference count to 1.
*/
- wxObjectRefData();
+ wxRefCounter();
/**
Decrements the reference count associated with this shared data and, if
- it reaches zero, destroys this instance of wxObjectRefData releasing its
+ it reaches zero, destroys this instance of wxRefCounter releasing its
memory.
Please note that after calling this function, the caller should
wxObject can be used to implement @ref overview_refcount "reference counted"
objects, such as wxPen, wxBitmap and others
(see @ref overview_refcount_list "this list").
- See wxObjectRefData and @ref overview_refcount for more info about
+ See wxRefCounter and @ref overview_refcount for more info about
reference counting.
@library{wxbase}
@category{rtti}
@see wxClassInfo, @ref overview_debugging, @ref overview_refcount,
- wxObjectRefData, wxObjectDataPtr<T>
+ wxObjectDataRef, wxObjectDataPtr<T>
*/
class wxObject
{