#include <RefCountedPtr.H>
This is to be used as a pointer to class T. This will feel and smell just like a built-in pointer except:
This class is completely inlined.
typical usage:
{ Box b; IntVect a; //refCount() == 1 RefCountedPtr<IntVectSet> set(new IntVectSet()); // still just one IntVectSet, but refCount()==2 RefCountedPtr<IntVectSet> otherSet(set); // Like a pointer, modifying one modifies the other otherSet->define(b); (*set)|=a; { RefCountedPtr<IntVectSet> anotherSet; // null anotherSet = otherSet ; //now all three have refCount()==3 }//anotherSet out of scope, so deleted. IntVectSet NOT deleted. // set.refCount() == 2 // otherSet.refCount() == 2; // otherset == set; } // when all RefCountedPtr's for a given object are deleted, the last // one calls 'delete' on the member pointer.
Public Member Functions | |
RefCountedPtr (T *ptr=0) | |
RefCountedPtr (const RefCountedPtr< T > &other) | |
~RefCountedPtr () | |
const RefCountedPtr< T > & | operator= (const RefCountedPtr< T > &rhs) |
assignement operator. copies pointer member | |
T * | operator-> () |
dereference access operator. use like a pointer derefence access function. | |
const T * | operator-> () const |
bool | isNull () const |
T & | operator* () |
pointer dereference. | |
const T & | operator* () const |
operator const T * () const | |
auto conversion to regular const pointer where required. | |
bool | isNonUnique () const |
true when refcount is one. | |
int | refCount () const |
void | swap (RefCountedPtr< T > &b) |
template<class T2> | |
operator RefCountedPtr< T2 > () | |
Template Conversion. | |
void | neverDelete () |
Protected Attributes | |
T * | ptr_ |
int * | refCount_ |
Friends | |
class | RefCountedPtr |
RefCountedPtr< T >::RefCountedPtr | ( | T * | ptr = 0 |
) | [inline, explicit] |
References MayDay::Error(), RefCountedPtr< T >::ptr_, and RefCountedPtr< T >::refCount_.
RefCountedPtr< T >::RefCountedPtr | ( | const RefCountedPtr< T > & | other | ) | [inline] |
References RefCountedPtr< T >::refCount_.
RefCountedPtr< T >::~RefCountedPtr | ( | ) | [inline] |
References RefCountedPtr< T >::ptr_, and RefCountedPtr< T >::refCount_.
const RefCountedPtr< T > & RefCountedPtr< T >::operator= | ( | const RefCountedPtr< T > & | rhs | ) | [inline] |
assignement operator. copies pointer member
copies pointer member and integer pointer, decreases refcount of rhs member before assignment. this refcount increased my one.
References RefCountedPtr< T >::ptr_, and RefCountedPtr< T >::refCount_.
T * RefCountedPtr< T >::operator-> | ( | ) | [inline] |
dereference access operator. use like a pointer derefence access function.
References MayDay::Error(), and RefCountedPtr< T >::ptr_.
const T * RefCountedPtr< T >::operator-> | ( | ) | const [inline] |
References MayDay::Error(), and RefCountedPtr< T >::ptr_.
bool RefCountedPtr< T >::isNull | ( | ) | const [inline] |
References RefCountedPtr< T >::ptr_.
T & RefCountedPtr< T >::operator* | ( | ) | [inline] |
const T & RefCountedPtr< T >::operator* | ( | ) | const [inline] |
References MayDay::Error(), and RefCountedPtr< T >::ptr_.
RefCountedPtr< T >::operator const T * | ( | ) | const [inline] |
bool RefCountedPtr< T >::isNonUnique | ( | ) | const [inline] |
int RefCountedPtr< T >::refCount | ( | ) | const [inline] |
void RefCountedPtr< T >::swap | ( | RefCountedPtr< T > & | b | ) | [inline] |
References RefCountedPtr< T >::ptr_, and RefCountedPtr< T >::refCount_.
Template Conversion.
provides a mechanism for the compiler to generate a conversion to a base class, like a real pointer would have
References RefCountedPtr< T >::ptr_, and RefCountedPtr< T >::refCount_.
void RefCountedPtr< T >::neverDelete | ( | ) | [inline] |
References RefCountedPtr< T >::refCount_.
friend class RefCountedPtr [friend] |
T* RefCountedPtr< T >::ptr_ [protected] |
Referenced by RefCountedPtr< T >::isNull(), RefCountedPtr< T >::operator const T *(), RefCountedPtr< T >::operator RefCountedPtr< T2 >(), RefCountedPtr< T >::operator*(), RefCountedPtr< T >::operator->(), RefCountedPtr< T >::operator=(), RefCountedPtr< T >::RefCountedPtr(), RefCountedPtr< T >::swap(), and RefCountedPtr< T >::~RefCountedPtr().
int* RefCountedPtr< T >::refCount_ [protected] |
Referenced by RefCountedPtr< T >::isNonUnique(), RefCountedPtr< T >::neverDelete(), RefCountedPtr< T >::operator RefCountedPtr< T2 >(), RefCountedPtr< T >::operator=(), RefCountedPtr< T >::refCount(), RefCountedPtr< T >::RefCountedPtr(), RefCountedPtr< T >::swap(), and RefCountedPtr< T >::~RefCountedPtr().