#include <Array.H>
Public Member Functions | |
Array () | |
Constructs an `Array<T>' with no elements. | |
Array (size_t len) | |
Constructs an `Array<T>' of size len with the value of each element defined by the default constructor for `T'. | |
Array (size_t len, const T &initialvalue) | |
Constructs an `Array<T>' of size len with the value of each elements given by initialvalue. | |
Array (const T *vec, size_t len) | |
Constructs an `Array<T>' of size len in which the K'th value is a copy of vec[K]. | |
int | size () const |
T & | operator[] (size_t i) |
Returns a reference to the K'th element in this `Array<T>'. | |
const T & | operator[] (size_t i) const |
Same as above, except acts on const Array's. | |
T & | get (size_t i) |
Different syntax for operator[] (long i). | |
const T & | get (size_t i) const |
Different syntax for const operator[] (long i). | |
T * | dataPtr () |
Returns pointer to vector of data. | |
const T * | dataPtr () const |
Same as above for constant arrays. | |
void | set (size_t i, const T &elem) |
Changes the i'th element of this `Array<T>' to elem. | |
void | swap (size_t i, size_t j) |
This function swaps the i'th and j'th element of the array. |
This class implements an array of objects of the parameterized type T. In contrast with the predefined C++ array type, an `Array<T>' object knows its size, can be dynamically resized, and provides automatic bounds checking. The bounds checking can be turned off by specifying the -DNDEBUG flag on the command line when compiling the BOXLIB library. The main reason for defining the ARRAY class is that it is used, either by composition or inheritance, to implement many of the other classes in the BOXLIB library.
The `Array<T>' class works by storing copies of the objects it contains. If the objects are large, such as `FARRAYBOX's it is probably better to use the `PArray' class which is an array class that stores pointers to the objects (avoiding expensive copies). The `Array<T>' class destructs all objects in the array when it is itself destructed. If this is not the desired action, the `PArray' class should be used.
In the Array<T> class, there are two different concepts of size: the amount of space allocated, and the amount of space actually used. Obviously, the allocated space must be larger than the used space. We separate these two concepts to allow the user to optionally avoid memory allocation costs. Rather than construct and destroy a temporary Array<T> many times, it may be less expensive to allocate it once with enough memory to handle all uses, and resize the Array<T> for each particular use. See the member functions `reserve', `shrinkWrap', and `resize'.
Note that care must be taken when deriving classes from `Array<T>'. It is a concrete class, not a polymorphic one.
This class does NOT provide an assignment operator for assigning an integer to an Array<T>.
Constructs an `Array<T>' of size len with the value of each element defined by the default constructor for `T'.
Constructs an `Array<T>' of size len with the value of each elements given by initialvalue.
Constructs an `Array<T>' of size len in which the K'th value is a copy of vec[K].
References BL_ASSERT, and Array< T >::operator[]().
int Array< T >::size | ( | ) | const [inline] |
Referenced by DistributionMapping::AddToCache(), VisMF::clear(), FabArrayCopyDescriptor< FAB >::CollectData(), FabArray< FAB >::copy(), DistributionMapping::define(), DistributionMapping::DistributionMapping(), RealDescriptor::format(), RealDescriptor::formatarray(), Array< T >::get(), VisMF::Header::Header(), IntVect::IntVect(), RealDescriptor::numBytes(), operator<<(), operator>>(), Array< T >::operator[](), RealDescriptor::order(), RealDescriptor::orderarray(), VisMF::Read(), PArray< T >::resize(), PArray< T >::size(), VisMF::VisMF(), and VisMF::Write().
T & Array< T >::operator[] | ( | size_t | i | ) | [inline] |
Returns a reference to the K'th element in this `Array<T>'.
The element can be modified through this reference. The result can be used as an L-value.
References BL_ASSERT, and Array< T >::size().
Referenced by Array< T >::Array(), Array< T >::dataPtr(), and Array< T >::get().
const T & Array< T >::operator[] | ( | size_t | i | ) | const [inline] |
T & Array< T >::get | ( | size_t | i | ) | [inline] |
Different syntax for operator[] (long i).
References BL_ASSERT, Array< T >::operator[](), and Array< T >::size().
const T & Array< T >::get | ( | size_t | i | ) | const [inline] |
T * Array< T >::dataPtr | ( | ) | [inline] |
Returns pointer to vector of data.
This function breaks object encapsulation and should only be used for interfacing to Fortran subroutines.
References Array< T >::operator[]().
Referenced by FabArrayCopyDescriptor< FAB >::CollectData(), RealDescriptor::format(), VisMF::Header::Header(), operator>>(), RealDescriptor::order(), VisMF::Read(), VisMF::VisMF(), and VisMF::Write().
const T * Array< T >::dataPtr | ( | ) | const [inline] |
void Array< T >::set | ( | size_t | i, | |
const T & | elem | |||
) | [inline] |
Changes the i'th element of this `Array<T>' to elem.
void Array< T >::swap | ( | size_t | i, | |
size_t | j | |||
) |
This function swaps the i'th and j'th element of the array.