PSCF v1.3
Util::DPArray< Data > Class Template Reference

A dynamic array that only holds pointers to its elements. More...

#include <DPArray.h>

Inheritance diagram for Util::DPArray< Data >:
Util::PArray< Data >

Public Member Functions

 DPArray ()
 Constructor.
 DPArray (DPArray< Data > const &other)
 Copy constructor, copy pointers.
virtual ~DPArray ()
 Destructor.
DPArray< Data > & operator= (DPArray< Data > const &other)
 Assignment, element by element.
void allocate (int capacity)
 Allocate an array of pointers to Data.
void append (Data &data)
 Append an element to the end of the sequence.
void clear ()
 Reset to empty state.
bool isAllocated () const
 Is this DPArray allocated?
Public Member Functions inherited from Util::PArray< Data >
virtual ~PArray ()
 Destructor.
int capacity () const
 Return allocated size.
int size () const
 Return logical size.
void begin (PArrayIterator< Data > &iterator) const
 Set a PArrayIterator to the beginning of this PArray.
void begin (ConstPArrayIterator< Data > &iterator) const
 Set a ConstPArrayIterator to the beginning of this PArray.
Data & operator[] (int i) const
 Mimic C array subscripting.

Additional Inherited Members

Protected Member Functions inherited from Util::PArray< Data >
 PArray ()
 Constructor (protected to prevent instantiation).
Protected Attributes inherited from Util::PArray< Data >
Data ** ptrs_
 PArray of of pointers to Data objects.
int capacity_
 Allocated size of ptrs_ array.
int size_
 Logical size (number of elements with initialized data).

Detailed Description

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

A dynamic array that only holds pointers to its elements.

Definition at line 24 of file DPArray.h.

Constructor & Destructor Documentation

◆ DPArray() [1/2]

template<typename Data>
Util::DPArray< Data >::DPArray ( )
inline

Constructor.

Definition at line 101 of file DPArray.h.

References Util::PArray< Data >::PArray().

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

◆ DPArray() [2/2]

template<typename Data>
Util::DPArray< Data >::DPArray ( DPArray< Data > const & other)

Copy constructor, copy pointers.

Allocates new Data* array and copies pointers to Data objects.

Parameters
otherthe DPArray to be copied.

Definition at line 111 of file DPArray.h.

References Util::PArray< Data >::capacity_, DPArray(), isAllocated(), Util::PArray< Data >::PArray(), Util::PArray< Data >::ptrs_, and Util::PArray< Data >::size_.

◆ ~DPArray()

template<typename Data>
Util::DPArray< Data >::~DPArray ( )
virtual

Destructor.

Deletes array of pointers, if allocated previously. Does not delete the associated Data objects.

Definition at line 177 of file DPArray.h.

References Util::PArray< Data >::capacity_, Util::Memory::deallocate(), Util::PArray< Data >::ptrs_, Util::PArray< Data >::size_, and ~DPArray().

Referenced by ~DPArray().

Member Function Documentation

◆ operator=()

template<typename Data>
DPArray< Data > & Util::DPArray< Data >::operator= ( DPArray< Data > const & other)

Assignment, element by element.

Preconditions:

  • Both this and other DPArrays must be allocated.
  • Capacity of this DPArray must be >= size of RHS DPArray.
Parameters
otherthe rhs DPArray

Definition at line 139 of file DPArray.h.

References Util::PArray< Data >::capacity_, DPArray(), operator=(), Util::PArray< Data >::ptrs_, Util::PArray< Data >::size_, and UTIL_THROW.

Referenced by operator=().

◆ allocate()

template<typename Data>
void Util::DPArray< Data >::allocate ( int capacity)

Allocate an array of pointers to Data.

Throw an Exception if the DPArray has already been allocated - A DPArray can only be allocated once.

Parameters
capacitynumber of elements to allocate.

Definition at line 191 of file DPArray.h.

References allocate(), Util::Memory::allocate(), Util::PArray< Data >::capacity(), Util::PArray< Data >::capacity_, Util::PArray< Data >::ptrs_, and UTIL_THROW.

Referenced by allocate().

◆ append()

template<typename Data>
void Util::DPArray< Data >::append ( Data & data)
inline

Append an element to the end of the sequence.

Parameters
dataData object to be appended

Definition at line 208 of file DPArray.h.

References append(), Util::PArray< Data >::capacity_, isAllocated(), Util::PArray< Data >::ptrs_, Util::PArray< Data >::size_, and UTIL_THROW.

Referenced by append().

◆ clear()

template<typename Data>
void Util::DPArray< Data >::clear ( )

Reset to empty state.

Definition at line 224 of file DPArray.h.

References clear(), isAllocated(), and Util::PArray< Data >::size_.

Referenced by clear().

◆ isAllocated()

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

Is this DPArray allocated?

Definition at line 235 of file DPArray.h.

References isAllocated(), and Util::PArray< Data >::ptrs_.

Referenced by append(), clear(), DPArray(), and isAllocated().


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