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

#include <ibtk/StaggeredPhysicalBoundaryHelper.h>

Classes

class  Allocator
 

Public Member Functions

 Array ()
 
 Array (const int n)
 
 Array (const int n, const Pointer< Arena > &pool)
 
 Array (const Array< TYPE > &rhs)
 
 Array (Array< TYPE > &&rhs)
 
 ~Array ()
 
Array< TYPE > & operator= (const Array< TYPE > &rhs)
 
Array< TYPE > & operator= (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)
 

Static Public Member Functions

static std::size_t getNumberOfAllocations ()
 

Private Member Functions

TYPE * allocateObjects (const int n, Arena *arena)
 
void deleteObjects ()
 

Private Attributes

TYPE * d_objects
 
ReferenceCounterd_counter
 
int d_elements
 

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

◆ Array() [1/5]

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

Create an array of zero elements.

◆ Array() [2/5]

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 standardnew'' operator.

◆ Array() [3/5]

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.

◆ Array() [4/5]

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

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.

◆ Array() [5/5]

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

Move constructor.

◆ ~Array()

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

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

◆ operator=() [1/2]

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

Copy 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.

◆ operator=() [2/2]

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

Move assignment. The moved-from array will be empty at the end of this function.

◆ operator[]() [1/2]

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

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.

◆ operator[]() [2/2]

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

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.

◆ isNull()

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

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

◆ setNull()

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

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.

◆ getPointer() [1/2]

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

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.

◆ getPointer() [2/2]

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

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.

◆ getSize()

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

Return the number of elements in the array.

◆ size()

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

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

◆ resizeArray() [1/2]

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.

◆ resizeArray() [2/2]

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.

◆ getNumberOfAllocations()

template<class TYPE >
static std::size_t SAMRAI::tbox::Array< TYPE >::getNumberOfAllocations ( )
static

Return the total number of allocations used by this particular Array class, e.g., Array<bool> or Array<double>.

This function is only intended for internal use.

◆ allocateObjects()

template<class TYPE >
TYPE* SAMRAI::tbox::Array< TYPE >::allocateObjects ( const int  n,
Arena arena 
)
private

◆ deleteObjects()

template<class TYPE >
void SAMRAI::tbox::Array< TYPE >::deleteObjects ( )
private

Member Data Documentation

◆ d_objects

template<class TYPE >
TYPE* SAMRAI::tbox::Array< TYPE >::d_objects
private

◆ d_counter

template<class TYPE >
ReferenceCounter* SAMRAI::tbox::Array< TYPE >::d_counter
mutableprivate

ReferenceCounter. To avoid extra allocations, d_counter == nullptr indicates that there is only one reference (the one owned by the current object).

◆ d_elements

template<class TYPE >
int SAMRAI::tbox::Array< TYPE >::d_elements
private

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