IBAMR  IBAMR version 0.19.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SAMRAI::tbox::ConstPointer< TYPE > Class Template Reference

#include <tbox/ConstPointer.h>

Inheritance diagram for SAMRAI::tbox::ConstPointer< TYPE >:
Inheritance graph
[legend]

Public Member Functions

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

Private Member Functions

void deleteObject ()
 
ReferenceCountergetSubclassReferenceCounter () const
 
const DescribedClassgetSubclassPointer () const
 

Private Attributes

const TYPE * d_object
 
ReferenceCounterd_counter
 

Detailed Description

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

Class ConstPointer<TYPE> defines a smart const 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 ConstPointer<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.

Const pointers can be created from either const or 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.

Class ConstPointer<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::ConstPointerBase
tbox::ReferenceCounter
tbox::PointerBase
tbox::Pointer

Constructor & Destructor Documentation

◆ ConstPointer() [1/5]

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::ConstPointer ( )

The default constructor creates a null pointer.

◆ ConstPointer() [2/5]

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::ConstPointer ( const 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.

◆ ConstPointer() [3/5]

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::ConstPointer ( const 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.

◆ ConstPointer() [4/5]

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::ConstPointer ( const ConstPointer< TYPE > &  ptr)

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

◆ ConstPointer() [5/5]

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::ConstPointer ( const ConstPointerBase 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.

◆ ~ConstPointer()

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::~ConstPointer ( )

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

◆ operator=() [1/3]

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

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

◆ operator=() [2/3]

template<class TYPE >
ConstPointer<TYPE>& SAMRAI::tbox::ConstPointer< TYPE >::operator= ( const 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.

◆ operator=() [3/3]

template<class TYPE >
ConstPointer<TYPE>& SAMRAI::tbox::ConstPointer< TYPE >::operator= ( const ConstPointerBase ptr)

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

◆ operator==()

template<class TYPE >
bool SAMRAI::tbox::ConstPointer< TYPE >::operator== ( const ConstPointer< TYPE > &  rhs) const

Check whether two smart pointers point to the same object.

◆ operator!=()

template<class TYPE >
bool SAMRAI::tbox::ConstPointer< TYPE >::operator!= ( const ConstPointer< TYPE > &  rhs) const

Check whether two smart pointers point to different objects.

◆ operator->()

template<class TYPE >
const TYPE* SAMRAI::tbox::ConstPointer< TYPE >::operator-> ( ) const

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.

◆ operator*()

template<class TYPE >
const TYPE& SAMRAI::tbox::ConstPointer< TYPE >::operator* ( ) const

Dereference the smart pointer. The pointer returned is a const pointer to the object.

◆ operator const TYPE *()

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::operator const TYPE * ( ) const

Implicit conversion of the smart pointer to the pointed-to object. The pointer returned is a const pointer to the object.

◆ getPointer()

template<class TYPE >
const TYPE* SAMRAI::tbox::ConstPointer< TYPE >::getPointer ( ) const

Explicitly convert the smart pointer to the pointed-to object. The pointer returned is a const pointer to the object.

◆ isNull()

template<class TYPE >
bool SAMRAI::tbox::ConstPointer< TYPE >::isNull ( ) const

Check whether the smart pointer points to NULL.

◆ operator bool()

template<class TYPE >
SAMRAI::tbox::ConstPointer< TYPE >::operator bool ( ) const

Return true if the pointer is non-NULL.

◆ operator!()

template<class TYPE >
bool SAMRAI::tbox::ConstPointer< TYPE >::operator! ( ) const

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

◆ setNull()

template<class TYPE >
void SAMRAI::tbox::ConstPointer< TYPE >::setNull ( )

Set the smart pointer to NULL.

◆ getReferenceCounter()

template<class TYPE >
ReferenceCounter* SAMRAI::tbox::ConstPointer< TYPE >::getReferenceCounter ( ) const

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

◆ deleteObject()

template<class TYPE >
void SAMRAI::tbox::ConstPointer< TYPE >::deleteObject ( )
private

◆ getSubclassReferenceCounter()

template<class TYPE >
ReferenceCounter* SAMRAI::tbox::ConstPointer< TYPE >::getSubclassReferenceCounter ( ) const
privatevirtual

◆ getSubclassPointer()

template<class TYPE >
const DescribedClass* SAMRAI::tbox::ConstPointer< TYPE >::getSubclassPointer ( ) const
privatevirtual

Member Data Documentation

◆ d_object

template<class TYPE >
const TYPE* SAMRAI::tbox::ConstPointer< TYPE >::d_object
private

◆ d_counter

template<class TYPE >
ReferenceCounter* SAMRAI::tbox::ConstPointer< TYPE >::d_counter
private

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