PSCF v1.5.0
Util::ConstArray< Data > Class Template Reference

Read-only array container class template. More...

#include <ConstArray.h>

Inheritance diagram for Util::ConstArray< Data >:
Pscf::HostRecvArray< Data, CPT > Pscf::HostRecvArray< Data, CUT >

Public Member Functions

Data const & operator[] (int i) const
 Get an element by const reference.
void begin (ConstArrayIterator< Data > &iterator) const
 Set a const iterator to begin this ConstArray.
Data const * cArray () const
 Return a pointer to the underlying C array (pointer to const data).
bool isAllocated () const
 Does this array have associated data?
int size () const
 Return logical size of this array.
int capacity () const
 Return allocated size of this array.

Protected Member Functions

 ConstArray ()
 Constructor (protected to prevent direct instantiation).
 ~ConstArray ()
 Destructor (protected to prevent direct destruction).

Protected Attributes

Data * data_
 Pointer to an array of Data elements.
int capacity_
 Allocated size of the data_ array.

Detailed Description

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

Read-only array container class template.

A ConstArray is a sequence container that supports random read-only access to elements via a operator [] that returns a const reference, or via a ConstArrayIterator. Similar to an Array, without any of the functions that provide write access to element values.

The ConstArray class template is designed to be used as only as a base class, and does not provide functions for memory management. The ConstArray template has a protected constructor and destructor to prevent direct direct construction or destruction, but to allow construction and destruction as a subojbect of a derived class.

When compiled in debug mode (i.e., when NDEBUG is not defined) the subscript operator [] checks the validity of the element index.

Definition at line 37 of file ConstArray.h.

Constructor & Destructor Documentation

◆ ConstArray()

template<typename Data>
Util::ConstArray< Data >::ConstArray ( )
inlineprotected

Constructor (protected to prevent direct instantiation).

Subclasses have responsibility for memory management.

Definition at line 125 of file ConstArray.h.

References capacity_, and data_.

◆ ~ConstArray()

template<typename Data>
Util::ConstArray< Data >::~ConstArray ( )
protected

Destructor (protected to prevent direct destruction).

Definition at line 136 of file ConstArray.h.

Member Function Documentation

◆ operator[]()

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

Get an element by const reference.

Mimics C-array subscripting.

Parameters
iarray index
Returns
const reference to element i

Definition at line 143 of file ConstArray.h.

References capacity_, and data_.

◆ begin()

template<typename Data>
void Util::ConstArray< Data >::begin ( ConstArrayIterator< Data > & iterator) const
inline

Set a const iterator to begin this ConstArray.

On return, iterator points to the first element of the array, and the iterator end pointer points one past the last element.

Parameters
iteratorConstArrayIterator, initialized on output

Definition at line 155 of file ConstArray.h.

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

◆ cArray()

template<typename Data>
Data const * Util::ConstArray< Data >::cArray ( ) const
inline

Return a pointer to the underlying C array (pointer to const data).

Definition at line 167 of file ConstArray.h.

References data_.

◆ isAllocated()

template<typename Data>
bool Util::ConstArray< Data >::isAllocated ( ) const
inline

◆ size()

template<typename Data>
int Util::ConstArray< Data >::size ( ) const
inline

Return logical size of this array.

Currently, capacity() == size(), always.

Returns
number of elements in this array

Definition at line 181 of file ConstArray.h.

References capacity_.

◆ capacity()

template<typename Data>
int Util::ConstArray< Data >::capacity ( ) const
inline

Member Data Documentation

◆ data_

◆ capacity_


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