UCommon
ucommon::CountedObject Class Reference

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

#include <object.h>

Inheritance diagram for ucommon::CountedObject:
Collaboration diagram for ucommon::CountedObject:

Public Member Functions

unsigned copied (void) const
 Return the number of active references (retentions) to our object.
 
bool is_copied (void) const
 Test if the object has copied references.
 
bool is_retained (void) const
 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.
 
- Public Member Functions inherited from ucommon::ObjectProtocol
ObjectProtocolcopy (void)
 Retain (increase retention of) object when copying.
 
void operator++ (void)
 Increase retention operator.
 
void operator-- (void)
 Decrease retention operator.
 
virtual ~ObjectProtocol ()
 Required virtual destructor.
 

Protected Member Functions

 CountedObject ()
 Construct a counted object, mark initially as unreferenced.
 
 CountedObject (const ObjectProtocol &ref)
 Construct a copy of a counted object.
 
virtual void dealloc (void)
 Dealloc object no longer referenced.
 
void reset (void)
 Force reset of 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()

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.

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

virtual 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.

◆ 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.

◆ 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 )
virtual

Decrease reference count when released.

If no longer retained, then the object is dealloc'd.

Implements ucommon::ObjectProtocol.

Reimplemented in ucommon::PagerObject.

◆ reset()

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

Force reset of count.

Definition at line 85 of file object.h.

◆ retain()

void ucommon::CountedObject::retain ( void )
virtual

Increase reference count when retained.

Implements ucommon::ObjectProtocol.

Reimplemented in ucommon::PagerObject.


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