Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

cbits::ref_ptr Class Template Reference

"Smart", thread-safe, reference-counting pointer. More...

#include <ref_ptr.h>

Inheritance diagram for cbits::ref_ptr:

[legend]
Collaboration diagram for cbits::ref_ptr:
[legend]
List of all members.

Public Methods

 ref_ptr (T *t)
 Create a pointer to T. More...

 ref_ptr (const ref_ptr< T > &r)
 Copy construct a pointer to T. More...

ref_ptr< T > & operator= (const ref_ptr< T > &r)
 Assign pointer to T. More...

const long getRefCount () const
 Access number of references. More...

bool operator== (const ref_ptr< T > &r)
 Test for equality to pointer T. More...

T * operator-> ()
 Access member of T. More...

T & operator * ()
 Access member of T. More...

virtual ~ref_ptr ()
 Destroy reference to T. More...


Protected Attributes

T * _t
 The underlying object. More...

long * _refs
 Number of references to the object. More...


Private Methods

void freeObject ()
 Free the object, the reference count var, and the 'mutex'. More...

void lock () const
 Lock this ptr (e.g. More...

void unlock () const
 Unlock this ptr. More...


Detailed Description

template<typename T>
class cbits::ref_ptr< T >

"Smart", thread-safe, reference-counting pointer.

Instead of:

 	A* a = new A(...);
 	a->...;
 
use
 	ref_ptr<A> a( new A(...) );
 	a->...;
 

Note that the reference counting semantics are thread-safe, but not necessarily the embedded object.


Constructor & Destructor Documentation

template<typename T>
cbits::ref_ptr< T >::ref_ptr T *    t [inline]
 

Create a pointer to T.

This sets the initial reference count to one (1).

template<typename T>
cbits::ref_ptr< T >::ref_ptr const ref_ptr< T > &    r [inline]
 

Copy construct a pointer to T.

This increments the reference count by one (1).

template<typename T>
virtual cbits::ref_ptr< T >::~ref_ptr   [inline, virtual]
 

Destroy reference to T.

This decrements the reference count by one (1). If no more references remain, the underlying object is deleted.


Member Function Documentation

template<typename T>
void cbits::ref_ptr< T >::freeObject   [inline, private]
 

Free the object, the reference count var, and the 'mutex'.

template<typename T>
const long cbits::ref_ptr< T >::getRefCount   const [inline]
 

Access number of references.

Returns:
long integer indicating number of references currently in existence for the underlying object.

template<typename T>
void cbits::ref_ptr< T >::lock   const [inline, private]
 

Lock this ptr (e.g.

while changing ref count).

template<typename T>
T& cbits::ref_ptr< T >::operator *   [inline]
 

Access member of T.

This doesn't affect the reference count.

Reimplemented in cbits::safe_ptr.

template<typename T>
T* cbits::ref_ptr< T >::operator->   [inline]
 

Access member of T.

This doesn't affect the reference count.

Reimplemented in cbits::safe_ptr.

template<typename T>
ref_ptr<T>& cbits::ref_ptr< T >::operator= const ref_ptr< T > &    r [inline]
 

Assign pointer to T.

This increments the reference count by one (1).

template<typename T>
bool cbits::ref_ptr< T >::operator== const ref_ptr< T > &    r [inline]
 

Test for equality to pointer T.

This doesn't affect the reference count.

template<typename T>
void cbits::ref_ptr< T >::unlock   const [inline, private]
 

Unlock this ptr.


Member Data Documentation

template<typename T>
long* cbits::ref_ptr::_refs [protected]
 

Number of references to the object.

template<typename T>
T* cbits::ref_ptr::_t [protected]
 

The underlying object.


The documentation for this class was generated from the following file:
Generated by
doxygen
Hosted by
SourceForge