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..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
ucommon::CountedObject Class Reference

A base class for reference counted objects. More...

#include <object.h>

Inheritance diagram for ucommon::CountedObject:
[legend]
Collaboration diagram for ucommon::CountedObject:
[legend]

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
 

Detailed Description

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.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 56 of file object.h.

Constructor & Destructor Documentation

◆ CountedObject() [1/2]

ucommon::CountedObject::CountedObject ( )
protected

Construct a counted object, mark initially as unreferenced.

Definition at line 28 of file object.cpp.

References count.

◆ CountedObject() [2/2]

ucommon::CountedObject::CountedObject ( const 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.

Definition at line 33 of file object.cpp.

References count.

Member Function Documentation

◆ copied()

unsigned ucommon::CountedObject::copied ( void  ) const
inline

Return the number of active references (retentions) to our object.

Returns
number of references to our object.

Definition at line 111 of file object.h.

◆ dealloc()

void ucommon::CountedObject::dealloc ( void  )
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().

◆ is_copied()

bool ucommon::CountedObject::is_copied ( void  ) const
inline

Test if the object has copied references.

This means that more than one object has a reference to our object.

Returns
true if referenced by more than one object.

Definition at line 95 of file object.h.

Referenced by ucommon::String::cow(), and ucommon::String::resize().

◆ is_retained()

bool ucommon::CountedObject::is_retained ( void  ) const
inline

Test if the object has been referenced (retained) by anyone yet.

Returns
true if retained.

Definition at line 103 of file object.h.

◆ release()

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().

Here is the call graph for this function:

◆ reset()

void ucommon::CountedObject::reset ( void  )
inlineprotected

Force reset of count.

Definition at line 85 of file object.h.

Referenced by ucommon::PagerObject::reset().

◆ retain()

Member Data Documentation

◆ count

volatile unsigned ucommon::CountedObject::count
private

Definition at line 59 of file object.h.

Referenced by CountedObject(), release(), and retain().


The documentation for this class was generated from the following files: