Simpatico
v1.10
|
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.
#include <DSArray.h>
Public Member Functions | |
DSArray () | |
Constructor. More... | |
DSArray (const DSArray< Data > &other) | |
Copy constructor. More... | |
DSArray< Data > & | operator= (const DSArray< Data > &other) |
Assignment, element by element. More... | |
virtual | ~DSArray () |
Destructor. More... | |
void | allocate (int capacity) |
Allocates the underlying C array. More... | |
void | append (const Data &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... | |
const Data & | 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... | |
Util::DSArray< Data >::DSArray | ( | ) |
Util::DSArray< Data >::DSArray | ( | const DSArray< Data > & | 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 |
Destructor.
Definition at line 233 of file DSArray.h.
References Util::DSArray< Data >::capacity_, Util::DSArray< Data >::data_, Util::DSArray< Data >::isAllocated(), and Util::DSArray< Data >::size_.
DSArray< Data > & Util::DSArray< Data >::operator= | ( | const DSArray< Data > & | 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 >::allocate(), Util::DSArray< Data >::capacity_, Util::DSArray< Data >::data_, 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::DSArray< Data >::capacity(), Util::DSArray< Data >::capacity_, Util::DSArray< Data >::data_, Util::DSArray< Data >::isAllocated(), Util::DSArray< Data >::size_, and UTIL_THROW.
Referenced by McMd::McMuExchange::loadParameters(), Util::DSArray< Data >::operator=(), McMd::McMuExchange::readParameters(), Tools::Configuration::readParameters(), and Util::DSArray< Data >::serialize().
|
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::DSArray< Data >::capacity_, Util::DSArray< Data >::data_, Util::DSArray< Data >::size_, and UTIL_THROW.
Referenced by McMd::McMuExchange::loadParameters(), and McMd::McMuExchange::readParameters().
|
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. |
The size parameter must be non-negative and may not exceed the capacity.
This function simply changes the logical size of without modifying any elements of the underlying physical array. If the size increases, added elements are uninitialized.
size | new logical size, 0 <= size < capacity. |
Definition at line 367 of file DSArray.h.
References Util::DSArray< Data >::size(), and Util::DSArray< Data >::size_.
|
inline |
Set logical size to zero.
Definition at line 374 of file DSArray.h.
References Util::DSArray< Data >::size_.
Referenced by Tools::Configuration::clear().
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::DSArray< Data >::allocate(), Util::DSArray< Data >::capacity(), Util::DSArray< Data >::capacity_, Util::DSArray< Data >::data_, Util::DSArray< Data >::isAllocated(), Util::DSArray< Data >::size_, and 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::DSArray< Data >::data_, Util::ArrayIterator< Data >::setCurrent(), Util::ArrayIterator< Data >::setEnd(), and Util::DSArray< Data >::size_.
Referenced by McMd::MdPairEnergyCoefficients::sample().
|
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::DSArray< Data >::data_, Util::ConstArrayIterator< Data >::setCurrent(), Util::ConstArrayIterator< Data >::setEnd(), and Util::DSArray< Data >::size_.
|
inline |
Mimic C array subscripting.
i | array index |
Definition at line 323 of file DSArray.h.
References Util::DSArray< Data >::data_, and Util::DSArray< Data >::size_.
|
inline |
Mimic C array subscripting.
i | array index |
Definition at line 334 of file DSArray.h.
References Util::DSArray< Data >::data_, and Util::DSArray< Data >::size_.
|
inline |
Return physical capacity of array.
Definition at line 381 of file DSArray.h.
References Util::DSArray< Data >::capacity_.
Referenced by Util::DSArray< Data >::allocate(), and Util::DSArray< Data >::serialize().
|
inline |
Return logical size of this array (i.e., number of elements).
Definition at line 388 of file DSArray.h.
References Util::DSArray< Data >::size_.
Referenced by Tools::DdMdConfigWriter::DdMdConfigWriter(), Tools::HoomdConfigReader::readConfig(), Util::DSArray< Data >::resize(), and McMd::McMuExchange::sample().
|
inline |
Return true if the DSArray has been allocated, false otherwise.
Definition at line 395 of file DSArray.h.
References Util::DSArray< Data >::data_.
Referenced by Util::DSArray< Data >::allocate(), Util::DSArray< Data >::DSArray(), Util::DSArray< Data >::operator=(), Util::DSArray< Data >::serialize(), and Util::DSArray< Data >::~DSArray().
|
protected |
C array of Data elements.
Definition at line 154 of file DSArray.h.
Referenced by Util::DSArray< Data >::allocate(), Util::DSArray< Data >::append(), Util::DSArray< Data >::begin(), Util::DSArray< Data >::DSArray(), Util::DSArray< Data >::isAllocated(), Util::DSArray< Data >::operator=(), Util::DSArray< Data >::operator[](), Util::DSArray< Data >::serialize(), and 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 >::allocate(), Util::DSArray< Data >::append(), Util::DSArray< Data >::begin(), Util::DSArray< Data >::clear(), Util::DSArray< Data >::DSArray(), Util::DSArray< Data >::operator=(), Util::DSArray< Data >::operator[](), Util::DSArray< Data >::resize(), Util::DSArray< Data >::serialize(), Util::DSArray< Data >::size(), and Util::DSArray< Data >::~DSArray().
|
protected |
Capacity (physical size) of underlying C array.
Definition at line 160 of file DSArray.h.
Referenced by Util::DSArray< Data >::allocate(), Util::DSArray< Data >::append(), Util::DSArray< Data >::capacity(), Util::DSArray< Data >::DSArray(), Util::DSArray< Data >::operator=(), Util::DSArray< Data >::serialize(), and Util::DSArray< Data >::~DSArray().