template <class T> class PP_Array

An Array of Objects of Type T for ParmParse

Inheritance:

PP_Array


public members:

PP_Array ()
PP_Array (long len)
PP_Array (long len, const T& initialvalue)
PP_Array (const T* vec, long len)
PP_Array (const PP_Array<T>& rhs)
PP_Array<T>& operator= (const PP_Array<T>& rhs)
~PP_Array ()
void clear ()
bool ready () const
void reserve (long _truesize)
void shrinkWrap ()
void resize (long newlen)
void resize (long newlen, const T& initialvalue)
long length () const
long trueSize () const
T& operator[] (long K)
const T& operator[] (long K) const
T& get (long i)
const T& get (long i) const
T* dataPtr ()
const T* dataPtr () const
void set (long i, const T& elem)
void swap (long i, long j)
bool operator== (const PP_Array<T>& rhs) const
bool operator!= (const PP_Array<T>& rhs) const

Documentation

This class implements an array of objects of the parameterized type T. In contrast with the predefined C++ array type, an `PP_Array<T>' object knows its length, 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 PP_Array class is that it is used, either by composition or inheritance, to implement many of the other classes in the BOXLIB library.

The `PP_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 `PP_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 PP_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 PP_Array<T> many times, it may be less expensive to allocate it once with enough memory to handle all uses, and resize the PP_Array<T> for each particular use. See the member functions `reserve', `shrinkWrap', and `resize'.

Note that care must be taken when deriving classes from `PP_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 PP_Array<T>.

This is a convenience class for ParmParse and will not be in any way supported by anyone at ANAG.

PP_Array ()
Constructs an `PP_Array<T>' with no elements

PP_Array (long len)
Constructs an `PP_Array<T>' of length len with the value of each element defined by the default constructor for `T'.

PP_Array (long len, const T& initialvalue)
Constructs an `PP_Array<T>' of length len with the value of each elements given by initialvalue.

PP_Array (const T* vec, long len)
Constructs an `PP_Array<T>' of length len in which the K'th value is a copy of vec[K].

PP_Array (const PP_Array<T>& rhs)
The copy constructor.

PP_Array<T>& operator= (const PP_Array<T>& rhs)
This operator deletes the current `PP_Array<T>' and replaces it with a copy of rhs.

~PP_Array ()
Deletes the `PP_Array<T>' and all objects it contains.

void clear ()
Destructs each element in this `PP_Array<T>'. The resulting array has length zero.

bool ready () const
Returns true if this `PP_Array<T>' is not empty.

void reserve (long _truesize)
Reserve space for future expansion of memory. You still must `resize' to address the memory.

void shrinkWrap ()
Shrink allocated memory to be just enough for elements in PP_Array. This is useful if you allocated a lot of memory to avoid memory allocation delays as you add elements. Once all the elements are added, you can reduce memory usage to the minimum by calling this function.

void resize (long newlen)
This function changes the size of this `PP_Array<T>' to newlen while preserving the value of as many array elements as possible. If newlen is greater than the current length, the array is grown and the new elements have the value given by the default constructor for `T'. If newlen is less than the current length the array is cropped with the remaining elements retaining their original values.

void resize (long newlen, const T& initialvalue)
This function changes the size of this `PP_Array<T>' to newlen while preserving the value of as many array elements as possible. If newlen is greater than the current length, the array is grown and the new elements have the value given by initialvalue. If newlen is less than the current length the array is cropped with the remaining elements retaining their original values.

long length () const
Return number of elements in the array.

long trueSize () const
Return the maximum number of elements the array can hold without doing a `resize'.

T& operator[] (long K)
Returns a reference to the K'th element in this `PP_Array<T>'. The element can be modified through this reference. The result can be used as an L-value.

const T& operator[] (long K) const
Same as above, except acts on const PP_Array's.

T& get (long i)
Different syntax for operator[] (long i).

const T& get (long i) const
Different syntax for const operator[] (long i).

T* dataPtr ()
Returns pointer to vector of data. This function breaks object encapsulation and should only be used for interfacing to Fortran subroutines.

const T* dataPtr () const
Same as above for constant PP_Arrays.

void set (long i, const T& elem)
Changes the i'th element of this `PP_Array<T>' to elem.

void swap (long i, long j)
This function swaps the i'th and j'th element of the PP_Array.

bool operator== (const PP_Array<T>& rhs) const
Test for equality.

bool operator!= (const PP_Array<T>& rhs) const
Test for inequality.


this class has no child classes.

alphabetic index hierarchy of classes


Chombo

Copyright Notice

This software is copyright (C) by the Lawrence Berkeley National Laboratory. Permission is granted to reproduce this software for non-commercial purposes provided that this notice is left intact.

It is acknowledged that the U.S. Government has rights to this software under Contract DE-AC03-765F00098 between the U.S. Department of Energy and the University of California.

This software is provided as a professional and academic contribution for joint exchange. Thus it is experimental, is provided ``as is'', with no warranties of any kind whatsoever, no support, no promise of updates, or printed documentation. By using this software, you acknowledge that the Lawrence Berkeley National Laboratory and Regents of the University of California shall have no liability with respect to the infringement of other copyrights by any part of this software.