Chombo + EB  3.2
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
RefCountedPtr< T, OP > Class Template Reference

A reference-counting handle class. More...

#include <RefCountedPtr.H>

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 More...
 
 RefCountedPtr (const Self &other)
 copy More...
 
 RefCountedPtr (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > &other)
 const converting copy adds const qualifier. More...
 
template<typename S >
 RefCountedPtr (const RefCountedPtr< S, OP > &other)
 related converting copy More...
 
template<typename OP2 >
 RefCountedPtr (const RefCountedPtr< T, OP2 > &other)
 
template<typename OP2 >
 RefCountedPtr (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &other)
 
 ~RefCountedPtr ()
 Destructor. More...
 
Selfoperator= (const Self &rhs)
 assignment operator copies pointer member More...
 
Selfoperator= (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > &rhs)
 const converting assignment operator adds const qualifier. More...
 
template<typename S >
Selfoperator= (const RefCountedPtr< S, OP > &rhs)
 related assignment operator More...
 
template<typename OP2 >
Selfoperator= (const RefCountedPtr< T, OP2 > &rhs)
 
template<typename OP2 >
Selfoperator= (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &rhs)
 
pointer operator-> () const
 dereference access operator used like a pointer derefence access function. More...
 
pointer const & getRefToThePointer () const
 Return a const reference to the pointer and don't ask questions. More...
 
reference operator* () const
 pointer dereference. More...
 
reference operator[] (const int a_idx) const
 [] access More...
 
 operator T * () const
 auto conversion to regular pointer where required. More...
 
bool isNull () const
 
bool isNonUnique () const
 true when refcount is one. More...
 
int refCount () const
 
void swap (Self &b)
 
void neverDelete ()
 Will never delete ptr_. More...
 
void incrementMem ()
 
void freeMem ()
 
 RefCountedPtr (RefCountedPtr< T, OP > &&a_in) noexcept
 move constructor More...
 
RefCountedPtr< T, OP > & operator= (RefCountedPtr< T, OP > &&a_in) noexcept
 
template<typename S >
RefCountedPtr< T, OP >::Selfoperator= (const RefCountedPtr< S, OP > &rhs)
 

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

template<typename T2 , typename OP2 >
class RefCountedPtr
 

Detailed Description

template<typename T, typename OP = RCPPointerPolicy>
class RefCountedPtr< T, OP >

A reference-counting handle class.

Template Parameters
TType of object pointed to
OPObject 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 is to be used as a pointer to class T. This will feel and smell just like a built-in pointer except:

    -#  There is no need to call delete on the pointer.
    -#  The default copy constructor and assignment implement ref-counting.
    -#  The user may call isNonUnique to determine if this pointer is
        the only pointer to the data.  This can be used to hide the
        ref-counting behavior of a class.
    -#  Checks for dereference of a null pointer.

This class is completely inlined.

typical usage:

{
Box b;
//refCount() == 1
// still just one IntVectSet, but refCount()==2
// 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.

Member Typedef Documentation

template<typename T, typename OP = RCPPointerPolicy>
typedef T RefCountedPtr< T, OP >::value_type
template<typename T, typename OP = RCPPointerPolicy>
typedef T* RefCountedPtr< T, OP >::pointer
template<typename T, typename OP = RCPPointerPolicy>
typedef T& RefCountedPtr< T, OP >::reference
template<typename T, typename OP = RCPPointerPolicy>
typedef RefCountedPtr<T, OP> RefCountedPtr< T, OP >::Self

Constructor & Destructor Documentation

template<typename T , typename OP >
RefCountedPtr< T, OP >::RefCountedPtr ( pointer const  ptr = 0)
inlineexplicit
template<typename T , typename OP >
RefCountedPtr< T, OP >::RefCountedPtr ( const Self other)
inline
template<typename T, typename OP>
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().

template<typename T , typename OP>
template<typename S >
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().

template<typename T, typename OP = RCPPointerPolicy>
template<typename OP2 >
RefCountedPtr< T, OP >::RefCountedPtr ( const RefCountedPtr< T, OP2 > &  other)
inline
template<typename T, typename OP = RCPPointerPolicy>
template<typename OP2 >
RefCountedPtr< T, OP >::RefCountedPtr ( const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &  other)
inline
template<typename T , typename OP >
RefCountedPtr< T, OP >::~RefCountedPtr ( )
inline

Destructor.

References RefCountedPtr< T, OP >::refDown().

template<typename T, typename OP = RCPPointerPolicy>
RefCountedPtr< T, OP >::RefCountedPtr ( RefCountedPtr< T, OP > &&  a_in)
inlinenoexcept

move constructor

Member Function Documentation

template<typename T , typename OP >
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().

template<typename T, typename OP>
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_.

template<typename T, typename OP = RCPPointerPolicy>
template<typename S >
Self& RefCountedPtr< T, OP >::operator= ( const RefCountedPtr< S, OP > &  rhs)

related assignment operator

allows conversion between related POD pointers. E.g. base to derived (requires dynamic_cast) or derived to base.

template<typename T, typename OP = RCPPointerPolicy>
template<typename OP2 >
Self& RefCountedPtr< T, OP >::operator= ( const RefCountedPtr< T, OP2 > &  rhs)
inline
template<typename T, typename OP = RCPPointerPolicy>
template<typename OP2 >
Self& RefCountedPtr< T, OP >::operator= ( const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &  rhs)
inline
template<typename T , typename OP >
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_.

template<typename T , typename OP >
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_.

template<typename T , typename OP >
RefCountedPtr< T, OP >::reference RefCountedPtr< T, OP >::operator* ( ) const
inline

pointer dereference.

References MayDay::Error(), and RefCountedPtr< T, OP >::ptr_.

template<typename T , typename OP >
RefCountedPtr< T, OP >::reference RefCountedPtr< T, OP >::operator[] ( const int  a_idx) const
inline

[] access

References CH_assert, and RefCountedPtr< T, OP >::ptr_.

template<class T , typename OP >
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.

template<typename T , typename OP >
bool RefCountedPtr< T, OP >::isNull ( ) const
inline
template<typename T , typename OP >
bool RefCountedPtr< T, OP >::isNonUnique ( ) const
inline

true when refcount is one.

References RefCountedPtr< T, OP >::refCount_.

template<typename T , typename OP >
int RefCountedPtr< T, OP >::refCount ( ) const
inline
template<typename T , typename OP >
void RefCountedPtr< T, OP >::swap ( Self b)
inline
template<typename T , typename OP >
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_.

template<typename T, typename OP = RCPPointerPolicy>
static const std::string& RefCountedPtr< T, OP >::name ( )
inlinestatic
template<typename T , typename OP >
void RefCountedPtr< T, OP >::incrementMem ( )
inline
template<typename T , typename OP >
void RefCountedPtr< T, OP >::freeMem ( )
inline
template<typename T, typename OP = RCPPointerPolicy>
RefCountedPtr<T,OP>& RefCountedPtr< T, OP >::operator= ( RefCountedPtr< T, OP > &&  a_in)
inlinenoexcept
template<typename T , typename OP >
void RefCountedPtr< T, OP >::refUp ( )
inlineprotected
template<typename T , typename OP >
void RefCountedPtr< T, OP >::refDown ( )
inlineprotected
template<typename T, typename OP = RCPPointerPolicy>
template<typename S >
RefCountedPtr<T, OP>::Self& RefCountedPtr< T, OP >::operator= ( const RefCountedPtr< S, OP > &  rhs)
inline

Friends And Related Function Documentation

template<typename T, typename OP = RCPPointerPolicy>
template<typename T2 , typename OP2 >
friend class RefCountedPtr
friend

Member Data Documentation

template<typename T, typename OP = RCPPointerPolicy>
pointer RefCountedPtr< T, OP >::ptr_
protected
template<typename T, typename OP = RCPPointerPolicy>
int* RefCountedPtr< T, OP >::refCount_
protected
template<typename T, typename OP = RCPPointerPolicy>
std::string RefCountedPtr< T, OP >::name_
staticprotected
template<typename T, typename OP = RCPPointerPolicy>
BArena RefCountedPtr< T, OP >::s_Arena
staticprotected
template<typename T, typename OP = RCPPointerPolicy>
int RefCountedPtr< T, OP >::size_ = sizeof(T)+2*sizeof(int)
staticprotected

The documentation for this class was generated from the following file: