PSCF v1.1
|
An automatically growable array, analogous to a std::vector. More...
#include <GArray.h>
Public Member Functions | |
GArray () | |
Constructor. More... | |
GArray (GArray< Data > const &other) | |
Copy constructor, copy pointers. More... | |
GArray< Data > & | operator= (GArray< Data > const &other) |
Assignment, element by element. More... | |
virtual | ~GArray () |
Destructor. More... | |
void | reserve (int capacity) |
Reserve memory for specified number of elements. More... | |
void | deallocate () |
Deallocate (delete) underlying array of pointers. More... | |
void | clear () |
Reset to empty state. More... | |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize a GArray to/from an Archive. More... | |
void | begin (ArrayIterator< Data > &iterator) |
Set an ArrayIterator to the beginning of this Array. More... | |
void | begin (ConstArrayIterator< Data > &iterator) const |
Set a ConstArrayIterator to the beginning of this Array. More... | |
void | append (Data const &data) |
Append an element to the end of the sequence. More... | |
void | resize (int n) |
Resizes array so that it contains n elements. More... | |
Data & | operator[] (int i) |
Mimic C array subscripting. More... | |
Data const & | operator[] (int i) const |
Mimic C array subscripting. More... | |
int | capacity () const |
Return physical capacity of array. More... | |
int | size () const |
Return logical size of this array (i.e., current number of elements). More... | |
bool | isAllocated () const |
Is this array allocated? More... | |
An automatically growable array, analogous to a std::vector.
An GArray is an array that grows as needed as objects are appended. It has a logical size that grows when objects are appended, which is always less than or equal to the current physical capacity. If an object is added when the size is already equal to the capacity, the array will be resized and copied to a new location in memory. The elements of a GArray are deleted when the GArray is destroyed or deallocated.
Util::GArray< Data >::GArray |
Util::GArray< Data >::GArray | ( | GArray< Data > const & | other | ) |
Copy constructor, copy pointers.
Allocates new C-array and copies pointers to Data objects.
other | the GArray to be copied. |
Definition at line 203 of file GArray.h.
References Util::GArray< Data >::isAllocated().
|
virtual |
GArray< Data > & Util::GArray< Data >::operator= | ( | GArray< Data > const & | other | ) |
void Util::GArray< Data >::reserve | ( | int | capacity | ) |
Reserve memory for specified number of elements.
Resizes and copies array if requested capacity is less than the current capacity. Does nothing if requested capacity is greater than current capacity.
capacity | number of elements for which to reserve space. |
Definition at line 255 of file GArray.h.
References UTIL_THROW.
Referenced by Util::Polynomial< T >::operator*=(), Util::Polynomial< T >::operator=(), and Util::Polynomial< T >::Polynomial().
void Util::GArray< Data >::deallocate |
Deallocate (delete) underlying array of pointers.
Sets capacity and size to zero.
Definition at line 286 of file GArray.h.
Referenced by Util::Binomial::clear().
void Util::GArray< Data >::clear |
Reset to empty state.
Sets size to zero, but leaves capacity unchanged. Does not call destructor for deleted elements.
Definition at line 299 of file GArray.h.
Referenced by Util::Polynomial< T >::setToZero().
void Util::GArray< Data >::serialize | ( | Archive & | ar, |
const unsigned int | version | ||
) |
|
inline |
Set an ArrayIterator to the beginning of this Array.
iterator | ArrayIterator, initialized on output. |
Definition at line 405 of file GArray.h.
References Util::ArrayIterator< Data >::setCurrent(), and Util::ArrayIterator< Data >::setEnd().
|
inline |
Set a ConstArrayIterator to the beginning of this Array.
iterator | ConstArrayIterator, initialized on output. |
Definition at line 416 of file GArray.h.
References Util::ConstArrayIterator< Data >::setCurrent(), and Util::ConstArrayIterator< Data >::setEnd().
void Util::GArray< Data >::append | ( | Data const & | data | ) |
Append an element to the end of the sequence.
Resizes array if space is inadequate.
data | Data object to be appended |
Definition at line 306 of file GArray.h.
Referenced by Util::Polynomial< T >::operator*=(), Util::Polynomial< T >::operator+=(), Util::Polynomial< T >::operator-=(), Util::Polynomial< T >::operator=(), and Util::Polynomial< T >::Polynomial().
void Util::GArray< Data >::resize | ( | int | n | ) |
Resizes array so that it contains n elements.
This function changes the size of the array to n, and changes the capacity iff necesary to accomodate the change in size. Upon return, size is set to n. In what follows, "size" and "capacity" refer to values on entry:
If n < size, size is reset, but no destructors are called If n > size, all added elements are value initialized If n > capacity, new memory is allocated and the array is moved
n | desired number of elements |
Definition at line 339 of file GArray.h.
References UTIL_THROW.
Referenced by Util::Binomial::setup().
|
inline |
|
inline |
|
inline |
Return physical capacity of array.
Definition at line 448 of file GArray.h.
Referenced by Util::Binomial::clear().
|
inline |
Return logical size of this array (i.e., current number of elements).
Definition at line 455 of file GArray.h.
Referenced by pscfpp.file.File::__eq__(), pscfpp.text.Record::__init__(), pscfpp.file.File::__init__(), pscfpp.file.File::__repr__(), pscfpp.text.Record::__str__(), Util::Polynomial< T >::degree(), and Util::Polynomial< T >::operator*=().
|
inline |
Is this array allocated?
Definition at line 462 of file GArray.h.
Referenced by Util::GArray< Data >::GArray().