utils::CountedPtr< T > Class Template Reference

#include <countedptr.h>

List of all members.


Detailed Description

template<typename T>
class utils::CountedPtr< T >

Class for counted reference semantics.

It deletes the object to which it refers when the last CountedPtr that refers to it is destroyed.

Nicolai M. Josuttis (The C++ standard library: a tutorial and reference).

Notes from kindjal:

Definition at line 44 of file countedptr.h.

Public Member Functions

 CountedPtr (T *p=0)
 Constructor.
 ~CountedPtr (void) throw ()
 Destructor.
 CountedPtr (const CountedPtr< T > &p) throw ()
 Copy pointer (one more owner).
template<typename U>
 CountedPtr (const CountedPtr< U > &p) throw ()
 Copy pointer with static cast (one more owner).
CountedPtr< T > & operator= (const CountedPtr< T > &p) throw ()
 Assignment (unshare old and share new value).
T & operator * (void) const throw ()
 Access the value to which the pointer refers.
T * operator-> (void) const throw ()
 Access the pointer.
T * get (void) const throw ()
 Get the pointer (mimic std::auto_ptr::get()).

Private Member Functions

void dispose (void)
 Manage the counter and free memory.

Private Attributes

T * ptr
 pointer to the value
long * count
 shared number of owners

Friends

class CountedPtr


Constructor & Destructor Documentation

template<typename T>
utils::CountedPtr< T >::CountedPtr T *  p = 0  )  [inline, explicit]
 

Constructor.

Initialize pointer with existing pointer.

It is required that the pointer p is a return value of new.

Definition at line 54 of file countedptr.h.

template<typename T>
utils::CountedPtr< T >::~CountedPtr void   )  throw () [inline]
 

Destructor.

Delete value if this was the last owner.

Definition at line 66 of file countedptr.h.

template<typename T>
utils::CountedPtr< T >::CountedPtr const CountedPtr< T > &  p  )  throw () [inline]
 

Copy pointer (one more owner).

Definition at line 76 of file countedptr.h.

template<typename T>
template<typename U>
utils::CountedPtr< T >::CountedPtr const CountedPtr< U > &  p  )  throw () [inline, explicit]
 

Copy pointer with static cast (one more owner).

Definition at line 88 of file countedptr.h.


Member Function Documentation

template<typename T>
void utils::CountedPtr< T >::dispose void   )  [inline, private]
 

Manage the counter and free memory.

Definition at line 151 of file countedptr.h.

template<typename T>
T* utils::CountedPtr< T >::get void   )  const throw () [inline]
 

Get the pointer (mimic std::auto_ptr::get()).

Definition at line 139 of file countedptr.h.

template<typename T>
T& utils::CountedPtr< T >::operator * void   )  const throw () [inline]
 

Access the value to which the pointer refers.

Definition at line 117 of file countedptr.h.

template<typename T>
T* utils::CountedPtr< T >::operator-> void   )  const throw () [inline]
 

Access the pointer.

Definition at line 128 of file countedptr.h.

template<typename T>
CountedPtr<T>& utils::CountedPtr< T >::operator= const CountedPtr< T > &  p  )  throw () [inline]
 

Assignment (unshare old and share new value).

Definition at line 100 of file countedptr.h.


Friends And Related Function Documentation

template<typename T>
friend class CountedPtr [friend]
 

Definition at line 162 of file countedptr.h.


Member Data Documentation

template<typename T>
long* utils::CountedPtr< T >::count [private]
 

shared number of owners

Definition at line 160 of file countedptr.h.

template<typename T>
T* utils::CountedPtr< T >::ptr [private]
 

pointer to the value

Definition at line 159 of file countedptr.h.


The documentation for this class was generated from the following file:
Generated on Fri Mar 30 15:39:19 2007 for TMW Server by  doxygen 1.3.9.1