ucommon
7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
![]() ![]() |
A base class for reference counted objects. More...
#include <object.h>
Public Member Functions | |
bool | is_copied (void) const |
Test if the object has copied references. More... | |
bool | is_retained (void) const |
Test if the object has been referenced (retained) by anyone yet. More... | |
unsigned | copied (void) const |
Return the number of active references (retentions) to our object. More... | |
void | retain (void) __OVERRIDE |
Increase reference count when retained. More... | |
void | release (void) __OVERRIDE |
Decrease reference count when released. More... | |
Protected Member Functions | |
CountedObject () | |
Construct a counted object, mark initially as unreferenced. More... | |
CountedObject (const ObjectProtocol &ref) | |
Construct a copy of a counted object. More... | |
virtual void | dealloc (void) |
Dealloc object no longer referenced. More... | |
void | reset (void) |
Force reset of count. More... | |
Private Attributes | |
volatile unsigned | count |
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.
|
protected |
Construct a counted object, mark initially as unreferenced.
Definition at line 28 of file object.cpp.
References count.
|
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.
Definition at line 33 of file object.cpp.
References count.
|
inline |
|
protectedvirtual |
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, and ucommon::String::cstring.
Definition at line 38 of file object.cpp.
Referenced by release().
|
inline |
Test if the object has copied references.
This means that more than one object has a reference to our object.
Definition at line 95 of file object.h.
Referenced by ucommon::String::cow(), and ucommon::String::resize().
|
inline |
void ucommon::CountedObject::release | ( | void | ) |
Decrease reference count when released.
If no longer retained, then the object is dealloc'd.
Definition at line 48 of file object.cpp.
References count, and dealloc().
Referenced by ucommon::String::cow(), ucommon::String::operator=(), ucommon::PagerObject::release(), ucommon::String::release(), and ucommon::String::resize().
|
inlineprotected |
Force reset of count.
Definition at line 85 of file object.h.
Referenced by ucommon::PagerObject::reset().
void ucommon::CountedObject::retain | ( | void | ) |
Increase reference count when retained.
Definition at line 43 of file object.cpp.
References count.
Referenced by ucommon::String::cow(), ucommon::String::fill(), ucommon::String::operator=(), ucommon::String::resize(), ucommon::PagerObject::retain(), ucommon::String::retain(), ucommon::String::set(), ucommon::UString::set(), ucommon::String::String(), and ucommon::UString::UString().
|
private |
Definition at line 59 of file object.h.
Referenced by CountedObject(), release(), and retain().