UCommon
|
A base class for reference counted objects. More...
#include <object.h>
Public Member Functions | |
unsigned | copied (void) |
Return the number of active references (retentions) to our object. | |
bool | isCopied (void) |
Test if the object has copied references. | |
bool | isRetained (void) |
Test if the object has been referenced (retained) by anyone yet. | |
void | release (void) |
Decrease reference count when released. | |
void | retain (void) |
Increase reference count when retained. | |
Protected Member Functions | |
CountedObject () | |
Construct a counted object, mark initially as unreferenced. | |
CountedObject (ObjectProtocol &ref) | |
Construct a copy of a counted object. | |
virtual void | dealloc (void) |
Dealloc object no longer referenced. |
A base class for reference counted objects.
Reference counted objects keep track of how many objects refer to them and fall out of scope when they are no longer being referred to. This can be used to achieve automatic heap management when used in conjunction with smart pointers.
ucommon::CountedObject::CountedObject | ( | ObjectProtocol & | ref | ) | [protected] |
Construct a copy of a counted object.
Our instance is not a reference to the original object but a duplicate, so we do not retain the original and we do reset our count to mark as initially unreferenced.
unsigned ucommon::CountedObject::copied | ( | void | ) | [inline] |
virtual void ucommon::CountedObject::dealloc | ( | void | ) | [protected, virtual] |
Dealloc object no longer referenced.
The dealloc routine would commonly be used for a self delete to return the object back to a heap when it is no longer referenced.
Reimplemented in ucommon::PagerObject.
bool ucommon::CountedObject::isCopied | ( | void | ) | [inline] |
bool ucommon::CountedObject::isRetained | ( | void | ) | [inline] |
void ucommon::CountedObject::release | ( | void | ) | [virtual] |
Decrease reference count when released.
If no longer retained, then the object is dealloc'd.
Implements ucommon::ObjectProtocol.
Reimplemented in ucommon::PagerObject.