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

A reference-counting handle class. More...

#include <RefCountedPtr.H>

Inheritance diagram for RefCountedPtr< T >:
Inheritance graph
[legend]

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 More...
 
T * operator-> ()
 dereference access operator. use like a pointer derefence access function. More...
 
const T * operator-> () const
 
bool isNull () const
 
T & operator* ()
 pointer dereference. More...
 
const T & operator* () const
 
 operator const T * () const
 auto conversion to regular const pointer where required. More...
 
bool isNonUnique () const
 true when refcount is one. More...
 
int refCount () const
 
void swap (RefCountedPtr< T > &b)
 
template<class T2 >
 operator RefCountedPtr< T2 > ()
 Template Conversion. More...
 
void neverDelete ()
 
void increment ()
 
void decrement ()
 

Static Public Member Functions

static const std::string & name ()
 

Protected Attributes

T * ptr_
 
int * refCount_
 

Static Protected Attributes

static std::string name_
 
static BArena s_Arena
 
static int size_ = sizeof(T)+2*sizeof(int)
 

Friends

template<class T2 >
class RefCountedPtr
 

Detailed Description

template<class T>
class RefCountedPtr< T >

A reference-counting handle class.

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

Constructor & Destructor Documentation

◆ RefCountedPtr() [1/2]

template<class T>
RefCountedPtr< T >::RefCountedPtr ( T *  ptr = 0)
inlineexplicit

◆ RefCountedPtr() [2/2]

template<class T>
RefCountedPtr< T >::RefCountedPtr ( const RefCountedPtr< T > &  other)
inline

◆ ~RefCountedPtr()

template<class T >
RefCountedPtr< T >::~RefCountedPtr ( )
inline

Member Function Documentation

◆ operator=()

template<class T>
const RefCountedPtr< T > & RefCountedPtr< T >::operator= ( const RefCountedPtr< T > &  rhs)
inline

assignement operator. copies pointer member

copies pointer member and integer pointer, decreases refcount of rhs member before assignment. this refcount increased my one.

◆ operator->() [1/2]

template<class T >
T * RefCountedPtr< T >::operator-> ( )
inline

dereference access operator. use like a pointer derefence access function.

◆ operator->() [2/2]

template<class T >
const T * RefCountedPtr< T >::operator-> ( ) const
inline

◆ isNull()

template<class T >
bool RefCountedPtr< T >::isNull ( ) const
inline

◆ operator*() [1/2]

template<class T >
T & RefCountedPtr< T >::operator* ( )
inline

pointer dereference.

◆ operator*() [2/2]

template<class T >
const T & RefCountedPtr< T >::operator* ( ) const
inline

◆ operator const T *()

template<class T >
RefCountedPtr< T >::operator const T * ( ) const
inline

auto conversion to regular const pointer where required.

◆ isNonUnique()

template<class T >
bool RefCountedPtr< T >::isNonUnique ( ) const
inline

true when refcount is one.

◆ refCount()

template<class T >
int RefCountedPtr< T >::refCount ( ) const
inline

◆ swap()

template<class T>
void RefCountedPtr< T >::swap ( RefCountedPtr< T > &  b)
inline

◆ operator RefCountedPtr< T2 >()

template<class T >
template<class T2 >
RefCountedPtr< T >::operator RefCountedPtr< T2 > ( )
inline

Template Conversion.

provides a mechanism for the compiler to generate a conversion to a base class, like a real pointer would have

◆ neverDelete()

template<class T >
void RefCountedPtr< T >::neverDelete ( )
inline

◆ name()

template<class T>
static const std::string& RefCountedPtr< T >::name ( )
inlinestatic

◆ increment()

template<class T >
void RefCountedPtr< T >::increment ( )
inline

◆ decrement()

template<class T >
void RefCountedPtr< T >::decrement ( )
inline

Friends And Related Function Documentation

◆ RefCountedPtr

template<class T>
template<class T2 >
friend class RefCountedPtr
friend

Member Data Documentation

◆ ptr_

template<class T>
T* RefCountedPtr< T >::ptr_
protected

◆ refCount_

template<class T>
int* RefCountedPtr< T >::refCount_
protected

◆ name_

template<class T>
std::string RefCountedPtr< T >::name_
staticprotected

◆ s_Arena

template<class T>
BArena RefCountedPtr< T >::s_Arena
staticprotected

◆ size_

template<class T>
int RefCountedPtr< T >::size_ = sizeof(T)+2*sizeof(int)
staticprotected

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