Home C-Bits Package Documentation Project Page

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

cbits::safe_ptr Class Template Reference

"Smart", thread-safe, reference-counting pointer that also synchronizes all method calls to the underlying object. More...

#include <safe_ptr.h>

Inheritance diagram for cbits::safe_ptr:

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

Public Methods

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

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

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

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

sync_ptr< T > operator-> ()
 Access member of T. More...

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

virtual ~safe_ptr ()
 Destroy reference 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...


Protected Attributes

T * _t
 The underlying object. More...

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


Detailed Description

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

"Smart", thread-safe, reference-counting pointer that also synchronizes all method calls to the underlying object.

Instead of:

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


Constructor & Destructor Documentation

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

Create a pointer to T.

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

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

Copy construct a pointer to T.

This increments the reference count by one (1).

template<typename T>
virtual cbits::safe_ptr< T >::~safe_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>
const long cbits::ref_ptr< T >::getRefCount   const [inline, inherited]
 

Access number of references.

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

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

Access member of T.

This doesn't affect the reference count.

Reimplemented from cbits::ref_ptr.

template<typename T>
sync_ptr<T> cbits::safe_ptr< T >::operator->   [inline]
 

Access member of T.

This doesn't affect the reference count.

Reimplemented from cbits::ref_ptr.

template<typename T>
safe_ptr<T>& cbits::safe_ptr< T >::operator= const safe_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, inherited]
 

Test for equality to pointer T.

This doesn't affect the reference count.

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

Test for equality to pointer T.

This doesn't affect the reference count.


Member Data Documentation

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

Number of references to the object.

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

The underlying object.


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