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

An automatically growable PArray. More...

#include <GPArray.h>

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

Public Member Functions

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

Additional Inherited Members

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

Detailed Description

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

An automatically growable PArray.

An GPArray is a PArray that grows as needed as objects are appended. Like any PArray, it holds pointers to objects, rather than objects. The associated objects are not destroyed when a PArray is deallocated or destroyed.

Definition at line 28 of file GPArray.h.

Constructor & Destructor Documentation

◆ GPArray() [1/2]

template<typename Data >
Util::GPArray< Data >::GPArray
inline

Constructor.

Definition at line 113 of file GPArray.h.

◆ GPArray() [2/2]

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

Copy constructor, copy pointers.

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

Parameters
otherthe GPArray to be copied.

Definition at line 123 of file GPArray.h.

References Util::PArray< Data >::capacity_, Util::PArray< Data >::ptrs_, and Util::PArray< Data >::size_.

◆ ~GPArray()

template<typename Data >
Util::GPArray< Data >::~GPArray
virtual

Destructor.

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

Definition at line 174 of file GPArray.h.

References Util::Memory::deallocate().

Member Function Documentation

◆ operator=()

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

Assignment, element by element.

Preconditions:

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

Definition at line 158 of file GPArray.h.

References Util::PArray< Data >::size_.

◆ append()

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

Append an element to the end of the sequence.

Resizes array if space is inadequate.

Parameters
dataData object to be appended

Definition at line 233 of file GPArray.h.

◆ reserve()

template<typename Data >
void Util::GPArray< Data >::reserve ( int  capacity)

Reserve memory for specified number of elements.

Resizes and copies array if requested capacity is less than the current capacity. Does nothing if requested capacity is greater than current capacity.

Parameters
capacitynumber of elements for which to reserve space.

Definition at line 187 of file GPArray.h.

References UTIL_THROW.

◆ deallocate()

template<typename Data >
void Util::GPArray< Data >::deallocate

Deallocate (delete) underlying array of pointers.

Definition at line 219 of file GPArray.h.

◆ clear()

template<typename Data >
void Util::GPArray< Data >::clear
inline

Reset to empty state.

Definition at line 266 of file GPArray.h.

◆ isAllocated()

template<class Data >
bool Util::GPArray< Data >::isAllocated
inline

Is this GPArray allocated?

Definition at line 273 of file GPArray.h.


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