UCommon
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
ucommon::TypeRef::Counted Class Reference

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

#include <typeref.h>

Inheritance diagram for ucommon::TypeRef::Counted:
Inheritance graph
[legend]
Collaboration diagram for ucommon::TypeRef::Counted:
Collaboration graph
[legend]

Public Member Functions

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

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.

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


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