UCommon
ucommon::TypeRef Class Reference

Smart pointer base class for auto-retained objects. More...

#include <typeref.h>

Inherited by ucommon::ArrayRef, ucommon::MapRef, ucommon::SharedRef [protected], ucommon::typeref< T, R >, ucommon::typeref< const char * >, ucommon::typeref< const uint8_t * >, and ucommon::typeref_guard [protected].

Collaboration diagram for ucommon::TypeRef:

Data Structures

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

Public Member Functions

void clear (void)
 Manually release the current container.
 
unsigned copies () const
 Get number of references to container.
 
bool is_released (void)
 
 operator bool () const
 Check if pointer currently has a heap container.
 
bool operator! () const
 Check if we are currently not pointing to anything.
 
void set (const TypeRef &pointer)
 Set our smart pointer based on another pointer instance.
 
size_t size (void) const
 Get size of referenced heap object.
 
virtual ~TypeRef ()
 Destroy pointer when falling out of scope.
 

Static Public Member Functions

static void put (TypeRef &target, Counted *object)
 Special weak-public means to copy a container reference.
 

Protected Member Functions

void assign (const typeref_guard &ref)
 Assign from a guarded typeref.
 
void set (Counted *object)
 Set our smart pointer to a specific heap container.
 
 TypeRef ()
 Create a smart pointer referencing nothing.
 
 TypeRef (const TypeRef &pointer)
 Create a smart pointer based on another pointer.
 
 TypeRef (Counted *object)
 Create a smart pointer referencing an existing heap object.
 

Static Protected Member Functions

static caddr_t mem (caddr_t address)
 Adjust memory pointer to atomic boundry.
 

Protected Attributes

Countedref
 

Friends

class ArrayRef
 
class MapRef
 
class SharedRef
 
class TypeRelease
 

Detailed Description

Smart pointer base class for auto-retained objects.

The underlying container is heap allocated and page aligned. A heap object is automatically de-referenced by release during destruction. The smart pointer is a protected base class used to derive strongly typed templates.

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

Definition at line 68 of file typeref.h.

Constructor & Destructor Documentation

◆ TypeRef() [1/2]

ucommon::TypeRef::TypeRef ( Counted * object)
protected

Create a smart pointer referencing an existing heap object.

Parameters
objectto reference.

◆ TypeRef() [2/2]

ucommon::TypeRef::TypeRef ( const TypeRef & pointer)
protected

Create a smart pointer based on another pointer.

Both pointers then reference the same object.

Parameters
pointerinstance to share reference with.

◆ ~TypeRef()

virtual ucommon::TypeRef::~TypeRef ( )
virtual

Destroy pointer when falling out of scope.

This de-references the heap container.

Member Function Documentation

◆ copies()

unsigned ucommon::TypeRef::copies ( ) const

Get number of references to container.

Returns
total number of pointers referencing container.
Examples
string.cpp.

◆ mem()

static caddr_t ucommon::TypeRef::mem ( caddr_t address)
staticprotected

Adjust memory pointer to atomic boundry.

Parameters
addressthat was allocated.
Returns
address for actual atomic aligned object.

◆ operator bool()

ucommon::TypeRef::operator bool ( ) const
inline

Check if pointer currently has a heap container.

Returns
true if we are referencing a container.

Definition at line 238 of file typeref.h.

◆ operator!()

bool ucommon::TypeRef::operator! ( ) const
inline

Check if we are currently not pointing to anything.

Returns
true if not referencing a container.

Definition at line 246 of file typeref.h.

◆ put()

static void ucommon::TypeRef::put ( TypeRef & target,
Counted * object )
inlinestatic

Special weak-public means to copy a container reference.

This uses the base class container which is not public, so only derived type specific smart pointers can actually use this method. It is made public because making it protected actually makes it inaccessible to template derived classes.

Parameters
targetsmart pointer object to set.
objectto have it reference.

Definition at line 259 of file typeref.h.

Here is the call graph for this function:

◆ set() [1/2]

void ucommon::TypeRef::set ( const TypeRef & pointer)

Set our smart pointer based on another pointer instance.

If we are already referencing, we release the current container.

Parameters
pointerinstance to share reference with.

◆ set() [2/2]

void ucommon::TypeRef::set ( Counted * object)
protected

Set our smart pointer to a specific heap container.

If we were pointing to something already we release that.

Parameters
objectto reference.

◆ size()

size_t ucommon::TypeRef::size ( void ) const

Get size of referenced heap object.

Returns
size of container or 0 if none.
Examples
string.cpp.

Friends And Related Symbol Documentation

◆ ArrayRef

friend class ArrayRef
friend

Definition at line 71 of file typeref.h.

◆ MapRef

friend class MapRef
friend

Definition at line 73 of file typeref.h.

◆ SharedRef

friend class SharedRef
friend

Definition at line 72 of file typeref.h.

◆ TypeRelease

friend class TypeRelease
friend

Definition at line 74 of file typeref.h.

Field Documentation

◆ ref

Counted* ucommon::TypeRef::ref
protected

Definition at line 164 of file typeref.h.


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