UCommon
ucommon::TypeRef::Counted Class Reference

Heap base-class container for typeref objects. More...

#include <typeref.h>

Inheritance diagram for ucommon::TypeRef::Counted:
Collaboration diagram for ucommon::TypeRef::Counted:

Public Member Functions

unsigned copies () const
 Number of retains (smart pointers) referencing us.
 
TypeRelease * getRelease () const
 
bool is () const
 Is this object not empty?
 
void operator delete (void *address)
 Override delete to de-allocate actual heap.
 
void release ()
 Release a copy of this object.
 
void retain ()
 Retain a copy of this object.
 
- 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

 Counted (void *address, size_t size, TypeRelease *ar=NULL)
 Construction of aligned container.
 
virtual void dealloc (void)
 Release memory and delete object when no longer referenced.
 

Protected Attributes

union { 
 
   TypeRelease *   autorelease 
 
   Counted *   linkrelease 
 
};  
 
Atomic::counter count
 
unsigned offset
 
size_t size
 

Friends

class TypeRef
 
class TypeRelease
 

Detailed Description

Heap base-class container for typeref objects.

This uses atomic reference counters for thread safety with maximal performance. This is used as a protected base class used for strongly typed heap containers through templates.

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

Definition at line 86 of file typeref.h.

Constructor & Destructor Documentation

◆ Counted()

ucommon::TypeRef::Counted::Counted ( void * address,
size_t size,
TypeRelease * ar = NULL )
explicitprotected

Construction of aligned container.

This is used to inform the object of the underlying real address it exists on the heap since malloc is not assured to be atomically aligned by default.

Parameters
addressof actual allocation.
sizeof object allocated.
arpool to use

Member Function Documentation

◆ copies()

unsigned ucommon::TypeRef::Counted::copies ( ) const
inline

Number of retains (smart pointers) referencing us.

Returns
number of copies of pointers referencing.

Definition at line 134 of file typeref.h.

◆ dealloc()

virtual void ucommon::TypeRef::Counted::dealloc ( void )
protectedvirtual

Release memory and delete object when no longer referenced.

This gets called with the atomic reference counter < 1, such as when the last smart pointer de-references.

◆ getRelease()

TypeRelease * ucommon::TypeRef::Counted::getRelease ( ) const
inline

Definition at line 138 of file typeref.h.

◆ is()

bool ucommon::TypeRef::Counted::is ( ) const
inline

Is this object not empty?

Returns
true if not empty.

Definition at line 126 of file typeref.h.

◆ operator delete()

void ucommon::TypeRef::Counted::operator delete ( void * address)

Override delete to de-allocate actual heap.

This is used because the object is atomically aligned, but the heap may not be.

Parameters
addressof our object.

◆ release()

void ucommon::TypeRef::Counted::release ( )
virtual

Release a copy of this object.

Only when the reference count reaches 0 is it destroyed.

Implements ucommon::ObjectProtocol.

◆ retain()

void ucommon::TypeRef::Counted::retain ( )
virtual

Retain a copy of this object.

Usually a smart pointer referencing.

Implements ucommon::ObjectProtocol.

Friends And Related Symbol Documentation

◆ TypeRef

friend class TypeRef
friend

Definition at line 92 of file typeref.h.

◆ TypeRelease

friend class TypeRelease
friend

Definition at line 93 of file typeref.h.

Field Documentation

◆ autorelease

TypeRelease* ucommon::TypeRef::Counted::autorelease

Definition at line 96 of file typeref.h.

◆ count

Atomic::counter ucommon::TypeRef::Counted::count ( void )
mutableprotected

Definition at line 100 of file typeref.h.

◆ linkrelease

Counted* ucommon::TypeRef::Counted::linkrelease

Definition at line 97 of file typeref.h.

◆ offset

unsigned ucommon::TypeRef::Counted::offset
protected

Definition at line 101 of file typeref.h.

◆ size

size_t ucommon::TypeRef::Counted::size
protected

Definition at line 102 of file typeref.h.


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