#include <RefCountedPtr.H>
Inheritance diagram for RefCountedPtr< T >:
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) |
Protected Attributes | |
T * | ptr_ |
int * | refCount_ |
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 RefCounterPtr<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.
|
|
|
|
|
|
|
true when refcount is one.
|
|
|
|
|
|
pointer dereference.
|
|
auto conversion to regular const pointer where required.
|
|
|
|
dereference access operator. use like a pointer derefence access function.
|
|
assignement operator. copies pointer member copies pointer member and integer pointer, decreases refcount of rhs member before assignment. this refcount increased my one. |
|
|
|
|
|
|
|
|