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

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

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.

Constructor & Destructor Documentation

◆ DSArray() [1/2]

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

Constructor.

Definition at line 170 of file DSArray.h.

◆ DSArray() [2/2]

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

◆ ~DSArray()

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

Destructor.

Definition at line 233 of file DSArray.h.

Member Function Documentation

◆ operator=()

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

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

◆ allocate()

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

◆ append()

template<class Data >
void Util::DSArray< Data >::append ( Data const &  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_THROW.

◆ resize()

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.

Definition at line 365 of file DSArray.h.

◆ clear()

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

Set logical size to zero.

Definition at line 372 of file DSArray.h.

◆ serialize()

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

Serialize a DSArray to/from an Archive.

Parameters
ararchive
versionarchive version id

Definition at line 265 of file DSArray.h.

References UTIL_THROW.

◆ begin() [1/2]

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::ArrayIterator< Data >::setCurrent(), and Util::ArrayIterator< Data >::setEnd().

◆ begin() [2/2]

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::ConstArrayIterator< Data >::setCurrent(), and Util::ConstArrayIterator< Data >::setEnd().

◆ operator[]() [1/2]

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.

◆ operator[]() [2/2]

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

◆ capacity()

template<class Data >
int Util::DSArray< Data >::capacity
inline

Return physical capacity of array.

Definition at line 379 of file DSArray.h.

◆ size()

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

◆ isAllocated()

template<class Data >
bool Util::DSArray< Data >::isAllocated
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=().

Member Data Documentation

◆ data_

template<typename Data >
Data* Util::DSArray< Data >::data_
protected

C array of Data elements.

Definition at line 154 of file DSArray.h.

Referenced by Util::DSArray< Data >::DSArray().

◆ size_

template<typename Data >
int Util::DSArray< Data >::size_
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=().

◆ capacity_

template<typename Data >
int Util::DSArray< Data >::capacity_
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=().


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