Simpatico  v1.10
List of all members | Public Member Functions | Protected Attributes
Util::DSArray< Data > Class Template Reference

Detailed Description

template<typename Data>
class Util::DSArray< Data >

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.

Definition at line 30 of file DSArray.h.

#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...
 

Constructor & Destructor Documentation

template<class Data >
Util::DSArray< Data >::DSArray ( )

Constructor.

Definition at line 170 of file DSArray.h.

template<class Data>
Util::DSArray< Data >::DSArray ( const DSArray< Data > &  other)

Copy constructor.

Parameters
otherthe 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.

template<class Data >
Util::DSArray< Data >::~DSArray ( )
virtual

Member Function Documentation

template<class Data>
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.

Parameters
otherthe 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.

template<class Data >
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.

Parameters
capacitynumber 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().

template<class Data>
void Util::DSArray< Data >::append ( const Data &  data)
inline

Append data to the end of the array.

Parameters
dataData 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().

template<class Data >
void Util::DSArray< Data >::resize ( int  size)
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.

Parameters
sizenew 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.

Parameters
sizenew logical size, 0 <= size < capacity.

Definition at line 367 of file DSArray.h.

References Util::DSArray< Data >::size(), and Util::DSArray< Data >::size_.

template<class Data >
void Util::DSArray< Data >::clear ( )
inline

Set logical size to zero.

Definition at line 374 of file DSArray.h.

References Util::DSArray< Data >::size_.

Referenced by Tools::Configuration::clear().

template<class Data >
template<class Archive >
void Util::DSArray< Data >::serialize ( Archive &  ar,
const unsigned int  version 
)
template<class Data>
void Util::DSArray< Data >::begin ( ArrayIterator< Data > &  iterator)
inline

Set an ArrayIterator to the beginning of this Array.

Parameters
iteratorArrayIterator, 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().

template<class Data>
void Util::DSArray< Data >::begin ( ConstArrayIterator< Data > &  iterator) const
inline

Set a ConstArrayIterator to the beginning of this Array.

Parameters
iteratorConstArrayIterator, 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_.

template<class Data >
Data & Util::DSArray< Data >::operator[] ( int  i)
inline

Mimic C array subscripting.

Parameters
iarray index
Returns
reference to element i

Definition at line 323 of file DSArray.h.

References Util::DSArray< Data >::data_, and Util::DSArray< Data >::size_.

template<class Data >
const Data & Util::DSArray< Data >::operator[] ( int  i) const
inline

Mimic C array subscripting.

Parameters
iarray index
Returns
const reference to element i

Definition at line 334 of file DSArray.h.

References Util::DSArray< Data >::data_, and Util::DSArray< Data >::size_.

template<class Data >
int Util::DSArray< Data >::capacity ( ) const
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().

template<class Data >
int Util::DSArray< Data >::size ( ) const
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().

template<class Data >
bool Util::DSArray< Data >::isAllocated ( ) const
inline

Member Data Documentation

template<typename Data>
Data* Util::DSArray< Data >::data_
protected
template<typename Data>
int Util::DSArray< Data >::size_
protected
template<typename Data>
int Util::DSArray< Data >::capacity_
protected

The documentation for this class was generated from the following file: