#include <RefCountedPtr.H>
T | Type of object pointed to | |
OP | Object Policy for T. If T* is an object pointer, use the RCPPointerPolicy. If T* is an array, use the RCPArrayPolicy to get proper destruction. If T* requires deletion with 'free', use the RCPFreePolicy. By default RCPPointerPolicy is used. |
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 Types | |
typedef T | value_type |
typedef T * | pointer |
typedef T & | reference |
typedef RefCountedPtr< T, OP > | Self |
Public Member Functions | |
RefCountedPtr (pointer const ptr=0) | |
construct with POD pointer | |
RefCountedPtr (const Self &other) | |
copy | |
RefCountedPtr (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > &other) | |
const converting copy adds const qualifier. | |
template<typename S> | |
RefCountedPtr (const RefCountedPtr< S, OP > &other) | |
related converting copy | |
template<typename OP2> | |
RefCountedPtr (const RefCountedPtr< T, OP2 > &other) | |
template<typename OP2> | |
RefCountedPtr (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &other) | |
~RefCountedPtr () | |
Destructor. | |
Self & | operator= (const Self &rhs) |
assignment operator copies pointer member | |
Self & | operator= (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > &rhs) |
const converting assignment operator adds const qualifier. | |
template<typename S> | |
Self & | operator= (const RefCountedPtr< S, OP > &rhs) |
related assignment operator | |
template<typename OP2> | |
Self & | operator= (const RefCountedPtr< T, OP2 > &rhs) |
template<typename OP2> | |
Self & | operator= (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &rhs) |
pointer | operator-> () const |
dereference access operator used like a pointer derefence access function. | |
pointer const & | getRefToThePointer () const |
Return a const reference to the pointer and don't ask questions. | |
reference | operator* () const |
pointer dereference. | |
reference | operator[] (const int a_idx) const |
[] access | |
operator T * () const | |
auto conversion to regular pointer where required. | |
bool | isNull () const |
bool | isNonUnique () const |
true when refcount is one. | |
int | refCount () const |
void | swap (Self &b) |
void | neverDelete () |
Will never delete ptr_. | |
void | incrementMem () |
void | freeMem () |
RefCountedPtr (RefCountedPtr< T, OP > &&a_in) noexcept | |
move constructor | |
RefCountedPtr< T, OP > & | operator= (RefCountedPtr< T, OP > &&a_in) noexcept |
Static Public Member Functions | |
static const std::string & | name () |
Protected Member Functions | |
void | refUp () |
void | refDown () |
Protected Attributes | |
pointer | ptr_ |
int * | refCount_ |
Static Protected Attributes | |
static std::string | name_ |
static BArena | s_Arena |
static int | size_ = sizeof(T)+2*sizeof(int) |
Friends | |
class | RefCountedPtr |
typedef T RefCountedPtr< T, OP >::value_type |
typedef T* RefCountedPtr< T, OP >::pointer |
typedef T& RefCountedPtr< T, OP >::reference |
typedef RefCountedPtr<T, OP> RefCountedPtr< T, OP >::Self |
RefCountedPtr< T, OP >::RefCountedPtr | ( | pointer const | ptr = 0 |
) | [inline, explicit] |
construct with POD pointer
References MayDay::Error(), RefCountedPtr< T, OP >::incrementMem(), pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refCount_.
RefCountedPtr< T, OP >::RefCountedPtr | ( | const Self & | other | ) | [inline] |
RefCountedPtr< T, OP >::RefCountedPtr | ( | const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > & | other | ) | [inline] |
const converting copy adds const qualifier.
the related converting copy could be used but this avoids the dynamic_cast when just adding qualifiers
References pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refUp().
RefCountedPtr< T, OP >::RefCountedPtr | ( | const RefCountedPtr< S, OP > & | other | ) | [inline] |
related converting copy
allows conversion between related POD pointers. E.g. base to derived (requires dynamic_cast) or derived to base.
References CH_assert, pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refUp().
RefCountedPtr< T, OP >::RefCountedPtr | ( | const RefCountedPtr< T, OP2 > & | other | ) | [inline] |
RefCountedPtr< T, OP >::RefCountedPtr | ( | const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > & | other | ) | [inline] |
RefCountedPtr< T, OP >::~RefCountedPtr | ( | ) | [inline] |
RefCountedPtr< T, OP >::RefCountedPtr | ( | RefCountedPtr< T, OP > && | a_in | ) | [inline] |
move constructor
RefCountedPtr< T, OP >::Self & RefCountedPtr< T, OP >::operator= | ( | const Self & | rhs | ) | [inline] |
assignment operator copies pointer member
copies pointer member and integer pointer, decreases 'this' refcount before assignment, then increases refcount of this=rhs.
References pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, RefCountedPtr< T, OP >::refCount_, RefCountedPtr< T, OP >::refDown(), and RefCountedPtr< T, OP >::refUp().
RefCountedPtr< T, OP >::Self & RefCountedPtr< T, OP >::operator= | ( | const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > & | rhs | ) | [inline] |
const converting assignment operator adds const qualifier.
References RefCountedPtr< T, OP >::freeMem(), pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refCount_.
RefCountedPtr< T, OP >::Self & RefCountedPtr< T, OP >::operator= | ( | const RefCountedPtr< S, OP > & | rhs | ) | [inline] |
related assignment operator
allows conversion between related POD pointers. E.g. base to derived (requires dynamic_cast) or derived to base.
References CH_assert, RefCountedPtr< T, OP >::freeMem(), pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refCount_.
Self& RefCountedPtr< T, OP >::operator= | ( | const RefCountedPtr< T, OP2 > & | rhs | ) | [inline] |
Self& RefCountedPtr< T, OP >::operator= | ( | const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > & | rhs | ) | [inline] |
RefCountedPtr< T, OP >::pointer RefCountedPtr< T, OP >::operator-> | ( | ) | const [inline] |
dereference access operator used like a pointer derefence access function.
References MayDay::Error(), and RefCountedPtr< T, OP >::ptr_.
RefCountedPtr< T, OP >::pointer const & RefCountedPtr< T, OP >::getRefToThePointer | ( | ) | const [inline] |
Return a const reference to the pointer and don't ask questions.
Same as operator -> but obtains the reference even if the pointer has not yet been assigned. Used in some early setup where we want to track the RCP but it hasn't been defined yet. If you want the pointer and know it has been allocated, -> should be preferred.
References RefCountedPtr< T, OP >::ptr_.
RefCountedPtr< T, OP >::reference RefCountedPtr< T, OP >::operator* | ( | ) | const [inline] |
RefCountedPtr< T, OP >::reference RefCountedPtr< T, OP >::operator[] | ( | const int | a_idx | ) | const [inline] |
RefCountedPtr< T, OP >::operator T * | ( | ) | const [inline] |
auto conversion to regular pointer where required.
kind of dangerous. Deleting the returned pointer will cause havoc.
References pout(), RefCountedPtr< T, OP >::ptr_, and RCPDBG.
bool RefCountedPtr< T, OP >::isNull | ( | ) | const [inline] |
References RefCountedPtr< T, OP >::ptr_.
Referenced by Scheduler::PeriodicFunctionLessThan::operator()(), and BCHolder::setTime().
bool RefCountedPtr< T, OP >::isNonUnique | ( | ) | const [inline] |
int RefCountedPtr< T, OP >::refCount | ( | ) | const [inline] |
References RefCountedPtr< T, OP >::refCount_.
Referenced by EBISLayout::refCount(), and BoxLayout::refCount().
void RefCountedPtr< T, OP >::swap | ( | Self & | b | ) | [inline] |
References RefCountedPtr< T, OP >::ptr_, and RefCountedPtr< T, OP >::refCount_.
Referenced by RefCountedPtr< DataFactory< NodeFArrayBox > >::operator=().
void RefCountedPtr< T, OP >::neverDelete | ( | ) | [inline] |
Will never delete ptr_.
useful in functions that need to return a pointer which, under some circumstances, we want to own, and under others we don't.
References RefCountedPtr< T, OP >::refCount_.
static const std::string& RefCountedPtr< T, OP >::name | ( | ) | [inline, static] |
void RefCountedPtr< T, OP >::incrementMem | ( | ) | [inline] |
References RefCountedPtr< T, OP >::refCount_, RefCountedPtr< T, OP >::s_Arena, and RefCountedPtr< T, OP >::size_.
Referenced by RefCountedPtr< T, OP >::RefCountedPtr().
void RefCountedPtr< T, OP >::freeMem | ( | ) | [inline] |
References pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, RefCountedPtr< T, OP >::refCount_, and RefCountedPtr< T, OP >::s_Arena.
Referenced by RefCountedPtr< T, OP >::operator=(), and RefCountedPtr< T, OP >::refDown().
RefCountedPtr<T,OP>& RefCountedPtr< T, OP >::operator= | ( | RefCountedPtr< T, OP > && | a_in | ) | [inline] |
void RefCountedPtr< T, OP >::refUp | ( | ) | [inline, protected] |
References pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refCount_.
Referenced by RefCountedPtr< T, OP >::operator=(), and RefCountedPtr< T, OP >::RefCountedPtr().
void RefCountedPtr< T, OP >::refDown | ( | ) | [inline, protected] |
References RefCountedPtr< T, OP >::freeMem(), pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refCount_.
Referenced by RefCountedPtr< T, OP >::operator=(), and RefCountedPtr< T, OP >::~RefCountedPtr().
friend class RefCountedPtr [friend] |
pointer RefCountedPtr< T, OP >::ptr_ [protected] |
Referenced by RefCountedPtr< T, OP >::freeMem(), RefCountedPtr< T, OP >::getRefToThePointer(), RefCountedPtr< T, OP >::isNull(), RefCountedPtr< T, OP >::operator T *(), RefCountedPtr< T, OP >::operator*(), RefCountedPtr< T, OP >::operator->(), RefCountedPtr< T, OP >::operator=(), RefCountedPtr< DataFactory< NodeFArrayBox > >::operator=(), RefCountedPtr< T, OP >::operator[](), RefCountedPtr< T, OP >::RefCountedPtr(), RefCountedPtr< T, OP >::refDown(), RefCountedPtr< T, OP >::refUp(), and RefCountedPtr< T, OP >::swap().
int* RefCountedPtr< T, OP >::refCount_ [protected] |
Referenced by RefCountedPtr< T, OP >::freeMem(), RefCountedPtr< T, OP >::incrementMem(), RefCountedPtr< T, OP >::isNonUnique(), RefCountedPtr< T, OP >::neverDelete(), RefCountedPtr< T, OP >::operator=(), RefCountedPtr< DataFactory< NodeFArrayBox > >::operator=(), RefCountedPtr< T, OP >::refCount(), RefCountedPtr< T, OP >::RefCountedPtr(), RefCountedPtr< T, OP >::refDown(), RefCountedPtr< T, OP >::refUp(), and RefCountedPtr< T, OP >::swap().
std::string RefCountedPtr< T, OP >::name_ [inline, static, protected] |
Referenced by RefCountedPtr< DataFactory< NodeFArrayBox > >::name().
BArena RefCountedPtr< T, OP >::s_Arena [inline, static, protected] |
Referenced by RefCountedPtr< T, OP >::freeMem(), and RefCountedPtr< T, OP >::incrementMem().
int RefCountedPtr< T, OP >::size_ = sizeof(T)+2*sizeof(int) [inline, static, protected] |
Referenced by RefCountedPtr< T, OP >::incrementMem().