#include <source/toolbox/memory/Array.h>
Inheritance diagram for SAMRAI::tbox::Array< TYPE >:
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) |
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.
SAMRAI::tbox::Array< TYPE >::Array | ( | ) | [inline] |
Create an array of zero elements.
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.
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.
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.
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.
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.
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.
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.
bool SAMRAI::tbox::Array< TYPE >::isNull | ( | ) | const [inline] |
Test whether the array is NULL (has any elements).
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.
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.
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.
int SAMRAI::tbox::Array< TYPE >::getSize | ( | ) | const [inline] |
Return the number of elements in the array.
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.
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.
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.