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

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

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

Inheritance graph
[legend]
List of all members.

Public Member Functions

 Array ()
 Array (const int n)
 Array (const int n, const Pointer< Arena > &pool)
 Array (const Array< TYPE > &rhs)
 ~Array ()
Array< TYPE > & operator= (const Array< TYPE > &rhs)
TYPE & operator[] (const int i)
const TYPE & operator[] (const int i) const
bool isNull () const
void setNull ()
TYPE * getPointer (const int i=0)
const TYPE * getPointer (const int i=0) const
int getSize () const
int size () const
void resizeArray (const int n)
void resizeArray (const int n, const Pointer< Arena > &pool)

Detailed Description

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

Class Array<TYPE> defines a smart pointer to an array of TYPE and manages all reference counting and deallocation of the array (even if the data was originally allocated from an arena). When the reference count on a Array<TYPE> object goes to zero, the array objects are automatically deallocated. The array class frees the user from deleting and tracking aliases for object arrays.

A block with references count and arena pointer is allocated for all non-empty arrays. These reference counted blocks are freed at the end of the lifetime of the array.

Class TYPE must define a default constructor and an assignment operator for the resize member function.

See also:
tbox::ReferenceCounter

tbox::Pointer


Constructor & Destructor Documentation

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

Create an array of zero elements.

template<class TYPE>
SAMRAI::tbox::Array< TYPE >::Array ( const int  n  ) 

Create an array of ``n'' elements. The storage for the objects is allocated via the standard ``new'' operator.

template<class TYPE>
SAMRAI::tbox::Array< TYPE >::Array ( const int  n,
const Pointer< Arena > &  pool 
)

Allocate an array of ``n'' elements using the memory arena. The storage for the objects is allocated from the specified arena; on deallocation, the storage will be returned to the arena.

template<class TYPE>
SAMRAI::tbox::Array< TYPE >::Array ( const Array< TYPE > &  rhs  )  [inline]

Const constructor for the array. This creates an alias to the right hand side and increments the reference count.

CAUTION: invoking resizeArray() forces a deep copy. Upon return, two objects that formerly were aliases to the same underlying data will point to separate data. For this reason, it is best to pass a Array by reference, instead of by value.

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

Destructor for the array. If the reference count for the array data has gone to zero, then the array data is deallocated from the memory arena from which it was allocated.


Member Function Documentation

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

Array assignment. The assignment operator copies a pointer to the array data and increments the reference count. Both array objects refer to the same data, and changes to individual array entry values in one will be reflected in the other array. However, this assignment operation DOES NOT involve a "deep copy" (see the resizeArray() routines below). Thus, changes to one Array object container will not necessarily be reflected in the other container.

template<class TYPE>
TYPE & SAMRAI::tbox::Array< TYPE >::operator[] ( const int  i  )  [inline]

Non-const array subscripting. Return a reference the object at array index ``i'' (between 0 and N-1, where N is the number of elements in the array.

template<class TYPE>
const TYPE & SAMRAI::tbox::Array< TYPE >::operator[] ( const int  i  )  const [inline]

Const array subscripting. Return a const reference to the object at array index ``i'' (between 0 and N-1, where N is the number of elements in the array.

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

Test whether the array is NULL (has any elements).

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

Set the length of the array to zero. If the reference count for the objects has dropped to zero, then the array data is deallocated.

template<class TYPE>
TYPE * SAMRAI::tbox::Array< TYPE >::getPointer ( const int  i = 0  )  [inline]

Return a non-const pointer to the i-th object. The index must be between 0 and N-1, where N is the number of elements in the array.

template<class TYPE>
const TYPE * SAMRAI::tbox::Array< TYPE >::getPointer ( const int  i = 0  )  const [inline]

Return a const pointer to the i-th object. The index must be between 0 and N-1, where N is the number of elements in the array.

template<class TYPE>
int SAMRAI::tbox::Array< TYPE >::getSize (  )  const [inline]

Return the number of elements in the array.

template<class TYPE>
int SAMRAI::tbox::Array< TYPE >::size (  )  const [inline]

Return the number of elements in the array. Identical to getSize(), but this method is common to several container classes.

template<class TYPE>
void SAMRAI::tbox::Array< TYPE >::resizeArray ( const int  n  ) 

Resize the array by allocating new array storage and copying from the old array into the new; i.e., a "deep" copy. Space for the new array is allocated via the standard ``new'' operator.

template<class TYPE>
void SAMRAI::tbox::Array< TYPE >::resizeArray ( const int  n,
const Pointer< Arena > &  pool 
)

Resize the array by allocating new array storage from the provided memory pool and copying from the old array into the new; i.e., a "deep" copy.


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