RefCountedPtr< T, OP > Class Template Reference

#include <RefCountedPtr.H>

List of all members.


Detailed Description

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

A reference-counting handle class.

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

  1. There is no need to call delete on the pointer.
  2. The default copy constructor and assignment implement ref-counting.
  3. 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.
  4. Checks for dereference of a null pointer.

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.
Selfoperator= (const Self &rhs)
 assignment operator copies pointer member
Selfoperator= (const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP > &rhs)
 const converting assignment operator adds const qualifier.
template<typename S>
Selfoperator= (const RefCountedPtr< S, OP > &rhs)
 related assignment operator
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.
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 ()

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

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  )  [inline, explicit]

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().


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>
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.

References CH_assert, RefCountedPtr< T, OP >::freeMem(), pout(), RefCountedPtr< T, OP >::ptr_, RCPDBG, and RefCountedPtr< T, OP >::refCount_.

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 (  )  [inline, static]

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>
void RefCountedPtr< T, OP >::refUp (  )  [inline, protected]

template<typename T, typename OP>
void RefCountedPtr< T, OP >::refDown (  )  [inline, protected]


Friends And Related Function Documentation

template<typename T, typename OP = RCPPointerPolicy>
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_ [inline, static, protected]

template<typename T, typename OP = RCPPointerPolicy>
BArena RefCountedPtr< T, OP >::s_Arena [inline, static, protected]

template<typename T, typename OP = RCPPointerPolicy>
int RefCountedPtr< T, OP >::size_ = sizeof(T)+2*sizeof(int) [inline, static, protected]


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

Generated on Sat Jul 22 04:03:57 2017 for Chombo + EB by  doxygen 1.5.5