PSCF v1.2
Util::FSArray< T, N > Class Template Reference

A fixed capacity (static) contiguous array with a variable logical size. More...

#include <FSArray.h>

Public Member Functions

 FSArray ()
 Constructor.
 
 FSArray (FSArray< Data, Capacity > const &other)
 Copy constructor.
 
FSArray< Data, Capacity > & operator= (FSArray< Data, Capacity > const &other)
 Assignment, element by element.
 
virtual ~FSArray ()
 Destructor.
 
int capacity () const
 Return physical capacity of array.
 
int size () const
 Return logical size of this array (i.e., number of elements).
 
void begin (ArrayIterator< Data > &iterator)
 Set an ArrayIterator to the beginning of this container.
 
void begin (ConstArrayIterator< Data > &iterator) const
 Set a ConstArrayIterator to the beginning of this container.
 
Data & operator[] (int i)
 Mimic C array subscripting.
 
Data const & operator[] (int i) const
 Mimic C array subscripting.
 
void append (Data const &data)
 Append data to the end of the array.
 
void clear ()
 Set logical size to zero.
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize to/from an archive.
 
int packedSize ()
 Packed size of FSArray in a MemoryArchive, in bytes.
 

Protected Attributes

Data data_ [Capacity]
 Array of Data elements.
 
int size_
 Logical size of array (number of elements used).
 

Detailed Description

template<typename T, int N>
class Util::FSArray< T, N >

A fixed capacity (static) contiguous array with a variable logical size.

An FSArray < Data, Capacity > is a wrapper for a statically allocated C array containing Capacity objects of type Data. An FSArray has both a Capacity that is set at compile time, which is the physical size of the underlying C array, and a logical size, which is the number of contiguous elements (from 0 to one less than its size) that contain valid data. The size is initialized to zero, and can only be increased only by the append() method, which adds a new element to the end of the array.

When compiled in debug mode (i.e., when NDEBUG is defined) the subcript operator [] checks that the index is less than the logical size, and not merely less than the capacity.

Definition at line 28 of file rpg/System.h.

Constructor & Destructor Documentation

◆ FSArray() [1/2]

template<class Data , int Capacity>
Util::FSArray< Data, Capacity >::FSArray ( )
inline

Constructor.

Definition at line 148 of file FSArray.h.

◆ FSArray() [2/2]

template<class Data , int Capacity>
Util::FSArray< Data, Capacity >::FSArray ( FSArray< Data, Capacity > const & other)

Copy constructor.

Parameters
otherthe FSArray to be copied.

Definition at line 158 of file FSArray.h.

◆ ~FSArray()

template<class Data , int Capacity>
Util::FSArray< Data, Capacity >::~FSArray ( )
virtual

Destructor.

Definition at line 193 of file FSArray.h.

Member Function Documentation

◆ operator=()

template<class Data , int Capacity>
FSArray< Data, Capacity > & Util::FSArray< Data, Capacity >::operator= ( FSArray< Data, Capacity > const & other)

Assignment, element by element.

Capacity of LHS FSArray must be >= size of RHS FSArray.

Parameters
otherthe RHS FSArray

Definition at line 175 of file FSArray.h.

◆ capacity()

template<class Data , int Capacity>
int Util::FSArray< Data, Capacity >::capacity ( ) const

Return physical capacity of array.

Definition at line 200 of file FSArray.h.

◆ size()

◆ begin() [1/2]

template<class Data , int Capacity>
void Util::FSArray< Data, Capacity >::begin ( ArrayIterator< Data > & iterator)

Set an ArrayIterator to the beginning of this container.

Parameters
iteratorArrayIterator, initialized on output.

Definition at line 216 of file FSArray.h.

References Util::ArrayIterator< Data >::setCurrent(), and Util::ArrayIterator< Data >::setEnd().

◆ begin() [2/2]

template<class Data , int Capacity>
void Util::FSArray< Data, Capacity >::begin ( ConstArrayIterator< Data > & iterator) const

Set a ConstArrayIterator to the beginning of this container.

Parameters
iteratorConstArrayIterator, initialized on output.

Definition at line 226 of file FSArray.h.

References Util::ConstArrayIterator< Data >::setCurrent(), and Util::ConstArrayIterator< Data >::setEnd().

◆ operator[]() [1/2]

template<class Data , int Capacity>
Data & Util::FSArray< Data, Capacity >::operator[] ( int i)

Mimic C array subscripting.

Parameters
iarray index
Returns
reference to element i

Definition at line 236 of file FSArray.h.

◆ operator[]() [2/2]

template<class Data , int Capacity>
Data const & Util::FSArray< Data, Capacity >::operator[] ( int i) const

Mimic C array subscripting.

Parameters
iarray index
Returns
const reference to element i

Definition at line 247 of file FSArray.h.

◆ append()

template<class Data , int Capacity>
void Util::FSArray< Data, Capacity >::append ( Data const & data)
inline

Append data to the end of the array.

Parameters
dataData to add to end of array.

Definition at line 258 of file FSArray.h.

References UTIL_THROW.

Referenced by Pscf::Rpc::Block< D >::computeStress(), Pscf::Rpg::Block< D >::computeStress(), and Pscf::Prdc::UnitCellBase< D >::parameters().

◆ clear()

template<class Data , int Capacity>
void Util::FSArray< Data, Capacity >::clear ( )
inline

Set logical size to zero.

Definition at line 271 of file FSArray.h.

◆ serialize()

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

Serialize to/from an archive.

Parameters
ararchive
versionarchive version id

Definition at line 280 of file FSArray.h.

References UTIL_THROW.

◆ packedSize()

template<typename Data , int Capacity>
int Util::FSArray< Data, Capacity >::packedSize ( )
inline

Packed size of FSArray in a MemoryArchive, in bytes.

Definition at line 296 of file FSArray.h.

Member Data Documentation

◆ data_

template<typename T , int N>
Data Util::FSArray< T, N >::data_[Capacity]
protected

Array of Data elements.

Definition at line 137 of file FSArray.h.

◆ size_

template<typename T , int N>
int Util::FSArray< T, N >::size_
protected

Logical size of array (number of elements used).

Definition at line 140 of file FSArray.h.


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