PSCF v1.5.0
Util::FPArray< Data, Capacity > Class Template Reference

Fixed size, stack allocated pointer array. More...

#include <FPArray.h>

Public Member Functions

 FPArray ()
 Default constructor.
 FPArray (FPArray< Data, Capacity > const &other)
 Copy constructor.
 ~FPArray ()
 Destructor.
FPArray< Data, Capacity > & operator= (FPArray< Data, Capacity > const &other)
 Assignment, element by element.
void append (Data &data)
 Append an element to the end of the array.
void clear ()
 Set logical size to zero and nullify all elements.
int capacity () const
 Return physical capacity of array.
int size () const
 Return logical size of this array.
void begin (PArrayIterator< Data > &iterator)
 Set an iterator to begin this container.
void begin (ConstPArrayIterator< Data > &iterator) const
 Set a const iterator to begin this container.
Data & operator[] (int i)
 Get an element by reference (mimic C-array subscripting).
Data const & operator[] (int i) const
 Get an element by const reference (mimic C-array subscripting).

Protected Attributes

Data * ptrs_ [Capacity]
 Array of pointers to Data objects.
int size_
 Logical size of array (number of elements used).

Detailed Description

template<typename Data, int Capacity>
class Util::FPArray< Data, Capacity >

Fixed size, stack allocated pointer array.

A FPArray is a fixed size array that holds pointers to Data objects, but for which the [] operator returns a reference to the associated object (i.e., to the deferenced pointer). It is implemented as a wrapper for a stack-allocated C array of Data* pointers. A FPArray is not responsible for destroying the associated Data objects.

The interface of an FPArray is identical to that of an FSArray. An FPArray has both a capacity that is set at compile time, which is the physical size of the underlying C array, and a size, which is the number of contiguous elements (indexed from 0 to size-1) that contain valid pointers. The size can only be increased only by the append() method, which takes a reference to an object as an argument, and adds an element to the end of the array.

When compiled in debug mode, the operator [] checks that the index is less than the size and non-negative.

Definition at line 41 of file FPArray.h.

Constructor & Destructor Documentation

◆ FPArray() [1/2]

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

Default constructor.

Definition at line 140 of file FPArray.h.

References ptrs_, and size_.

Referenced by FPArray(), and operator=().

◆ FPArray() [2/2]

template<typename Data, int Capacity>
Util::FPArray< Data, Capacity >::FPArray ( FPArray< Data, Capacity > const & other)

Copy constructor.

Copies all pointers.

Parameters
otherthe FPArray to be copied.

Definition at line 151 of file FPArray.h.

References FPArray(), ptrs_, and size_.

◆ ~FPArray()

template<typename Data, int Capacity>
Util::FPArray< Data, Capacity >::~FPArray ( )

Destructor.

Definition at line 207 of file FPArray.h.

Member Function Documentation

◆ operator=()

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

Assignment, element by element.

Parameters
otherthe rhs FPArray

Definition at line 177 of file FPArray.h.

References FPArray(), ptrs_, size_, and UTIL_THROW.

◆ append()

template<typename Data, int Capacity>
void Util::FPArray< Data, Capacity >::append ( Data & data)
inline

Append an element to the end of the array.

Parameters
dataData to add to end of array.

Definition at line 271 of file FPArray.h.

References ptrs_, size_, and UTIL_THROW.

◆ clear()

template<typename Data, int Capacity>
void Util::FPArray< Data, Capacity >::clear ( )
inline

Set logical size to zero and nullify all elements.

Definition at line 284 of file FPArray.h.

References ptrs_, and size_.

◆ capacity()

template<typename Data, int Capacity>
int Util::FPArray< Data, Capacity >::capacity ( ) const
inline

Return physical capacity of array.

Definition at line 214 of file FPArray.h.

◆ size()

template<typename Data, int Capacity>
int Util::FPArray< Data, Capacity >::size ( ) const
inline

Return logical size of this array.

Definition at line 221 of file FPArray.h.

References size_.

◆ begin() [1/2]

template<typename Data, int Capacity>
void Util::FPArray< Data, Capacity >::begin ( PArrayIterator< Data > & iterator)
inline

Set an iterator to begin this container.

Parameters
iteratorPArrayIterator, initialized on output.

Definition at line 228 of file FPArray.h.

References ptrs_, Util::PArrayIterator< Data >::setCurrent(), Util::PArrayIterator< Data >::setEnd(), and size_.

◆ begin() [2/2]

template<typename Data, int Capacity>
void Util::FPArray< Data, Capacity >::begin ( ConstPArrayIterator< Data > & iterator) const
inline

Set a const iterator to begin this container.

Parameters
iteratorConstPArrayIterator, initialized on output.

Definition at line 238 of file FPArray.h.

References ptrs_, Util::ConstPArrayIterator< Data >::setCurrent(), Util::ConstPArrayIterator< Data >::setEnd(), and size_.

◆ operator[]() [1/2]

template<typename Data, int Capacity>
Data & Util::FPArray< Data, Capacity >::operator[] ( int i)
inline

Get an element by reference (mimic C-array subscripting).

Parameters
iarray index
Returns
reference to element i

Definition at line 249 of file FPArray.h.

References ptrs_, and size_.

◆ operator[]() [2/2]

template<typename Data, int Capacity>
Data const & Util::FPArray< Data, Capacity >::operator[] ( int i) const
inline

Get an element by const reference (mimic C-array subscripting).

Parameters
iarray index
Returns
const reference to element i

Definition at line 260 of file FPArray.h.

References ptrs_, and size_.

Member Data Documentation

◆ ptrs_

template<typename Data, int Capacity>
Data* Util::FPArray< Data, Capacity >::ptrs_[Capacity]
protected

Array of pointers to Data objects.

Definition at line 127 of file FPArray.h.

Referenced by append(), begin(), begin(), clear(), FPArray(), FPArray(), operator=(), operator[](), and operator[]().

◆ size_

template<typename Data, int Capacity>
int Util::FPArray< Data, Capacity >::size_
protected

Logical size of array (number of elements used).

Definition at line 130 of file FPArray.h.

Referenced by append(), begin(), begin(), clear(), FPArray(), FPArray(), operator=(), operator[](), operator[](), and size().


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