SAMRAI::tbox::Pointer< TYPE > Class Template Reference

#include <source/toolbox/memory/Pointer.h>

Inheritance diagram for SAMRAI::tbox::Pointer< TYPE >:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 Pointer ()
 Pointer (TYPE *ptr, const bool managed=true)
 Pointer (TYPE *ptr, const Pointer< Arena > &pool)
 Pointer (const Pointer< TYPE > &ptr)
 Pointer (const PointerBase &ptr)
 ~Pointer ()
Pointer< TYPE > & operator= (const Pointer< TYPE > &ptr)
Pointer< TYPE > & operator= (TYPE *ptr)
Pointer< TYPE > & operator= (const PointerBase &ptr)
bool operator== (const Pointer< TYPE > &rhs) const
bool operator!= (const Pointer< TYPE > &rhs) const
TYPE * operator-> () const
TYPE & operator * () const
 operator TYPE * () const
TYPE * getPointer () const
bool isNull () const
 operator bool () const
bool operator! () const
void setNull ()
ReferenceCountergetReferenceCounter () const

Detailed Description

template<class TYPE>
class SAMRAI::tbox::Pointer< TYPE >

Class Pointer<TYPE> defines a smart pointer to TYPE. It frees the user from explicitly deleting and tracking aliases for object pointers. It manages all reference counting and deallocation of the pointer (even if the data was originally allocated from a memory arena). When the reference count on a Pointer<TYPE> object goes to zero, the object is automatically deallocated. A block with a references count and arena pointer is allocated for all non-NULL pointers. These reference counted blocks are freed at the end of the lifetime of the pointer.

Non-const pointers can be created only from other non-const pointers. The non-const and const pointer classes have been designed so that an attempted conversion from a const pointer into a non-const pointer causes a compile-time error. The const convention for this class is that any member function that does not change the pointer object itself may be const. Note that this means that a const pointer does not mean that the pointed-to object is const; these semantics require the const pointer class.

Class Pointer<TYPE> performs type-checking when assigning pointers of different TYPEs. If a bad type conversion is performed, then the destination pointer is set to NULL.

See also:
tbox::Array

tbox::ConstPointer

tbox::PointerBase

tbox::ReferenceCounter


Constructor & Destructor Documentation

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::Pointer (  )  [inline]

The default constructor creates a null pointer.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::Pointer ( TYPE *  ptr,
const bool  managed = true 
)

Create a smart pointer with value ptr. If managed is true, then deallocation of the object pointed to by ptr will be taken care of by the smart pointer. This form assumes the pointer was allocated using the standard new operator.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::Pointer ( TYPE *  ptr,
const Pointer< Arena > &  pool 
)

Create a smart pointer for which the data was allocated from pool. When the pointer is destroyed, the object is deallocated from the specified memory pool.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::Pointer ( const Pointer< TYPE > &  ptr  )  [inline]

The pointer const constructor creates a smart pointer reference aliased to the argument.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::Pointer ( const PointerBase ptr  ) 

Create a pointer by attempting to type-cast the argument to TYPE. If the type-cast fails, then the destination pointer will be set to NULL.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::~Pointer (  )  [inline]

The pointer destructor frees the pointer data if the reference count drops to zero. The object is deallocated from the memory pool (if it was specified in the constructor call).


Member Function Documentation

template<class TYPE>
Pointer< TYPE > & SAMRAI::tbox::Pointer< TYPE >::operator= ( const Pointer< TYPE > &  ptr  )  [inline]

Smart pointer assignment. The left hand side points to the right hand side and the reference count is incremented by one.

template<class TYPE>
Pointer< TYPE > & SAMRAI::tbox::Pointer< TYPE >::operator= ( TYPE *  ptr  ) 

Create a managed smart pointer with value ptr. The object pointed to by ptr will be deallocated via delete when the reference count goes to zero.

template<class TYPE>
Pointer< TYPE > & SAMRAI::tbox::Pointer< TYPE >::operator= ( const PointerBase ptr  ) 

Attempt to convert the argument pointer to a Pointer<TYPE>. If the type conversion fails, then the destination pointer will be set to NULL.

template<class TYPE>
bool SAMRAI::tbox::Pointer< TYPE >::operator== ( const Pointer< TYPE > &  rhs  )  const [inline]

Check whether two smart pointers point to the same object.

template<class TYPE>
bool SAMRAI::tbox::Pointer< TYPE >::operator!= ( const Pointer< TYPE > &  rhs  )  const [inline]

Check whether two smart pointers point to different objects.

template<class TYPE>
TYPE * SAMRAI::tbox::Pointer< TYPE >::operator-> (  )  const [inline]

Delegate member operations to the pointed-to object. C++ defines the ``->'' operator in a funny way to support delegation. The statement ptr->foo() acts as if ptr where actually a pointer to an object with member function foo() instead of a class that holds that pointer. This member function is const since it cannot change the pointer, although the pointed-to object may change.

template<class TYPE>
TYPE & SAMRAI::tbox::Pointer< TYPE >::operator * (  )  const [inline]

Dereference the smart pointer. This member function is const since it cannot change the pointer, although the pointed-to object may change.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::operator TYPE * (  )  const [inline]

Implicit conversion of the smart pointer to the pointed-to object. This conversion operator is const since it cannot change the pointer, although the pointed-to object may change.

template<class TYPE>
TYPE * SAMRAI::tbox::Pointer< TYPE >::getPointer (  )  const [inline]

Explicitly convert the smart pointer to the pointed-to object. This member function is const since it cannot change the pointer, although the pointed-to object may change.

template<class TYPE>
bool SAMRAI::tbox::Pointer< TYPE >::isNull (  )  const [inline]

Check whether the smart pointer points to NULL.

template<class TYPE>
SAMRAI::tbox::Pointer< TYPE >::operator bool (  )  const [inline]

Return true if the pointer is non-NULL.

template<class TYPE>
bool SAMRAI::tbox::Pointer< TYPE >::operator! (  )  const [inline]

Return true if the pointer is NULL and false otherwise. This operator mimics the semantics of !p applied to a (regular) pointer p.

template<class TYPE>
void SAMRAI::tbox::Pointer< TYPE >::setNull (  )  [inline]

Set the smart pointer to NULL.

template<class TYPE>
ReferenceCounter * SAMRAI::tbox::Pointer< TYPE >::getReferenceCounter (  )  const [inline]

Return a pointer to the internal reference counter. This routine should not be called by the casual user.


The documentation for this class was generated from the following files:
Generated on Thu Jun 18 11:29:04 2009 for SAMRAI by  doxygen 1.5.1