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
 

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

◆ value_type

template<typename T, typename OP = RCPPointerPolicy>
typedef T RefCountedPtr< T, OP >::value_type

◆ pointer

template<typename T, typename OP = RCPPointerPolicy>
typedef T* RefCountedPtr< T, OP >::pointer

◆ reference

template<typename T, typename OP = RCPPointerPolicy>
typedef T& RefCountedPtr< T, OP >::reference

◆ Self

template<typename T, typename OP = RCPPointerPolicy>
typedef RefCountedPtr<T, OP> RefCountedPtr< T, OP >::Self

Constructor & Destructor Documentation

◆ RefCountedPtr() [1/7]

template<typename T , typename OP >
RefCountedPtr< T, OP >::RefCountedPtr ( pointer const  ptr = 0)
inlineexplicit

construct with POD pointer

◆ RefCountedPtr() [2/7]

template<typename T , typename OP >
RefCountedPtr< T, OP >::RefCountedPtr ( const Self other)
inline

copy

◆ RefCountedPtr() [3/7]

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

◆ RefCountedPtr() [4/7]

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.

◆ RefCountedPtr() [5/7]

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

◆ RefCountedPtr() [6/7]

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

◆ ~RefCountedPtr()

template<typename T , typename OP >
RefCountedPtr< T, OP >::~RefCountedPtr ( )
inline

Destructor.

◆ RefCountedPtr() [7/7]

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

move constructor

Member Function Documentation

◆ operator=() [1/6]

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.

◆ operator=() [2/6]

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.

◆ operator=() [3/6]

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

◆ operator=() [4/6]

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

◆ operator=() [5/6]

template<typename T, typename OP = RCPPointerPolicy>
template<typename OP2 >
Self& RefCountedPtr< T, OP >::operator= ( const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &  rhs)
inline

◆ operator->()

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.

◆ getRefToThePointer()

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.

◆ operator*()

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

pointer dereference.

◆ operator[]()

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

[] access

◆ operator T*()

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.

◆ isNull()

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

◆ isNonUnique()

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

true when refcount is one.

◆ refCount()

template<typename T , typename OP >
int RefCountedPtr< T, OP >::refCount ( ) const
inline

Referenced by EBISLayout::refCount().

◆ swap()

template<typename T , typename OP >
void RefCountedPtr< T, OP >::swap ( Self b)
inline

◆ neverDelete()

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.

◆ name()

template<typename T, typename OP = RCPPointerPolicy>
static const std::string& RefCountedPtr< T, OP >::name ( )
inlinestatic

◆ incrementMem()

template<typename T , typename OP >
void RefCountedPtr< T, OP >::incrementMem ( )
inline

◆ freeMem()

template<typename T , typename OP >
void RefCountedPtr< T, OP >::freeMem ( )
inline

◆ operator=() [6/6]

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

◆ refUp()

template<typename T , typename OP >
void RefCountedPtr< T, OP >::refUp ( )
inlineprotected

◆ refDown()

template<typename T , typename OP >
void RefCountedPtr< T, OP >::refDown ( )
inlineprotected

Friends And Related Function Documentation

◆ RefCountedPtr

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

Member Data Documentation

◆ ptr_

template<typename T, typename OP = RCPPointerPolicy>
pointer RefCountedPtr< T, OP >::ptr_
protected

◆ refCount_

template<typename T, typename OP = RCPPointerPolicy>
int* RefCountedPtr< T, OP >::refCount_
protected

◆ name_

template<typename T, typename OP = RCPPointerPolicy>
std::string RefCountedPtr< T, OP >::name_
staticprotected

◆ s_Arena

template<typename T, typename OP = RCPPointerPolicy>
BArena RefCountedPtr< T, OP >::s_Arena
staticprotected

◆ size_

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: