class cref_ptr

Compact Reference Counted Pointer Class. More...

 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods

Detailed Description

The cref_ptr class is a strong reference class. It maintains a count of how many references to an object exist and releases the memory associated with the object when the reference count reaches zero. The reference pointer can be dereferenced like an ordinary pointer to call methods on the reference counted object.

In contrast to the ref_ptr class, accessing the pointer requires two levels of indirection as the pointer is stored in the same table as the counter. This is a performance hit, but means each cref_ptr only consumes 4-bytes.

At the time of writing the only supported memory management is through the new and delete operators. At a future date, this class should support the STL allocator classes or an equivalent to provide greater flexibility.

 cref_ptr (_Tp* __p = 0)


Construct a compact reference pointer for object.


ppointer to object to be reference counted. p must be allocated using operator new as it will be destructed using delete when the reference count reaches zero.
 cref_ptr (const cref_ptr& __r)


Copy Constructor

Constructs a reference pointer for object. Raises reference count associated with object by 1.

cref_ptr&  operator= (const cref_ptr& __r)


Assignment Operator

Assigns reference pointer to new object.

 ~cref_ptr ()


Destruct reference pointer instance and lower reference count on object being tracked. The object being tracked will be deleted if the reference count falls to zero because of the destruction of the reference pointer.

_Tp*  get ()



Dereference pointer to reference counted object.

Returns: pointer to object.

_Tp&  operator* ()



Dereference reference counted object.

Returns: reference to object.

_Tp*  operator-> ()



Dereference pointer to reference counted object.

Returns: pointer to object.

bool  operator== (const cref_ptr& rp)



Equality Operator

Returns: true if reference pointers refer to same object.

bool  is_empty ()



Check if reference pointer refers to an object or whether it has been assigned a null object.

Returns: true if reference pointer refers to a null object.

bool  is_only ()



Returns: true if reference pointer represents only reference to object.

bool  at_least (int32_t n)




nminimum count.

Returns: true if there are at least n references to object.

void  release ()



Release reference on object. The reference pointers underlying object is set to null, and the former object is destructed if necessary.

Generated by: pavlin on on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.