PSCF v1.1
|
Dynamically allocated array with variable logical size. More...
#include <DSArray.h>
Public Member Functions | |
DSArray () | |
Constructor. More... | |
DSArray (DSArray< Data > const &other) | |
Copy constructor. More... | |
DSArray< Data > & | operator= (DSArray< Data > const &other) |
Assignment, element by element. More... | |
virtual | ~DSArray () |
Destructor. More... | |
void | allocate (int capacity) |
Allocates the underlying C array. More... | |
void | append (Data const &data) |
Append data to the end of the array. More... | |
void | resize (int size) |
Modify logical size without modifying data. More... | |
void | clear () |
Set logical size to zero. More... | |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize a DSArray 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... | |
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., number of elements). More... | |
bool | isAllocated () const |
Return true if the DSArray has been allocated, false otherwise. More... | |
Protected Attributes | |
Data * | data_ |
C array of Data elements. More... | |
int | size_ |
Logical size of array (number of elements used). More... | |
int | capacity_ |
Capacity (physical size) of underlying C array. More... | |
Dynamically allocated array with variable logical size.
A DSArray < Data > is a wrapper for a dynamically allocated C array, with continuous elements and a logical size that may be less than or equal to its physical capacity. The logical size is the number of contiguous elements that have been added using the append() method.
Util::DSArray< Data >::DSArray |
Util::DSArray< Data >::DSArray | ( | DSArray< Data > const & | other | ) |
Copy constructor.
other | the DSArray to be copied. |
Definition at line 180 of file DSArray.h.
References Util::DSArray< Data >::capacity_, Util::DSArray< Data >::data_, Util::DSArray< Data >::isAllocated(), Util::DSArray< Data >::size_, and UTIL_THROW.
|
virtual |
DSArray< Data > & Util::DSArray< Data >::operator= | ( | DSArray< Data > const & | other | ) |
Assignment, element by element.
Capacity of LHS must be either zero or equal that of RHS DSArray.
other | the RHS DSArray |
Definition at line 204 of file DSArray.h.
References Util::DSArray< Data >::capacity_, Util::DSArray< Data >::isAllocated(), Util::DSArray< Data >::size_, and UTIL_THROW.
void Util::DSArray< Data >::allocate | ( | int | capacity | ) |
Allocates the underlying C array.
Throw an exception if the DSArray has already been allocated - A DSArray can only be allocated once.
capacity | number of elements to allocate |
Definition at line 247 of file DSArray.h.
References UTIL_THROW.
|
inline |
Append data to the end of the array.
data | Data to add to end of array. |
Definition at line 345 of file DSArray.h.
References UTIL_THROW.
|
inline |
Modify logical size without modifying data.
The size parameter must be non-negative and may not exceed the physical allocated capacity.
This function simply changes the logical size without modifying any elements of the underlying physical array. When the size increases, added elements are uninitialized.
size | new logical size, 0 <= size < capacity. |
|
inline |
void Util::DSArray< Data >::serialize | ( | Archive & | ar, |
const unsigned int | version | ||
) |
Serialize a DSArray to/from an Archive.
ar | archive |
version | archive version id |
Definition at line 265 of file DSArray.h.
References UTIL_THROW.
|
inline |
Set an ArrayIterator to the beginning of this Array.
iterator | ArrayIterator, initialized on output. |
Definition at line 302 of file DSArray.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 313 of file DSArray.h.
References Util::ConstArrayIterator< Data >::setCurrent(), and Util::ConstArrayIterator< Data >::setEnd().
|
inline |
|
inline |
|
inline |
|
inline |
Return logical size of this array (i.e., number of elements).
Definition at line 386 of file DSArray.h.
Referenced by pscfpp.file.File::__eq__(), pscfpp.text.Record::__init__(), pscfpp.file.File::__init__(), pscfpp.file.File::__repr__(), and pscfpp.text.Record::__str__().
|
inline |
Return true if the DSArray has been allocated, false otherwise.
Definition at line 393 of file DSArray.h.
Referenced by Util::DSArray< Data >::DSArray(), and Util::DSArray< Data >::operator=().
|
protected |
C array of Data elements.
Definition at line 154 of file DSArray.h.
Referenced by Util::DSArray< Data >::DSArray().
|
protected |
Logical size of array (number of elements used).
Definition at line 157 of file DSArray.h.
Referenced by Util::DSArray< Data >::DSArray(), and Util::DSArray< Data >::operator=().
|
protected |
Capacity (physical size) of underlying C array.
Definition at line 160 of file DSArray.h.
Referenced by Util::DSArray< Data >::DSArray(), and Util::DSArray< Data >::operator=().