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

An automatically growable array, analogous to a std::vector. More...

#include <GArray.h>

Inheritance diagram for Util::GArray< Data >:
Util::Polynomial< double > Util::Polynomial< T >

Public Member Functions

 GArray ()
 Constructor. More...
 
 GArray (GArray< Data > const &other)
 Copy constructor, copy pointers. More...
 
GArray< Data > & operator= (GArray< Data > const &other)
 Assignment, element by element. More...
 
virtual ~GArray ()
 Destructor. 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...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize a GArray to/from an Archive. More...
 
void begin (ArrayIterator< Data > &iterator)
 Set an ArrayIterator to the beginning of this Array. More...
 
void begin (ConstArrayIterator< Data > &iterator) const
 Set a ConstArrayIterator to the beginning of this Array. More...
 
void append (Data const &data)
 Append an element to the end of the sequence. More...
 
void resize (int n)
 Resizes array so that it contains n elements. More...
 
Data & operator[] (int i)
 Mimic C array subscripting. More...
 
Data const & operator[] (int i) const
 Mimic C array subscripting. More...
 
int capacity () const
 Return physical capacity of array. More...
 
int size () const
 Return logical size of this array (i.e., current number of elements). More...
 
bool isAllocated () const
 Is this array allocated? More...
 

Detailed Description

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

An automatically growable array, analogous to a std::vector.

An GArray is an array that grows as needed as objects are appended. It has a logical size that grows when objects are appended, which is always less than or equal to the current physical capacity. If an object is added when the size is already equal to the capacity, the array will be resized and copied to a new location in memory. The elements of a GArray are deleted when the GArray is destroyed or deallocated.

Definition at line 33 of file GArray.h.

Constructor & Destructor Documentation

◆ GArray() [1/2]

template<typename Data >
Util::GArray< Data >::GArray

Constructor.

Definition at line 191 of file GArray.h.

◆ GArray() [2/2]

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

Copy constructor, copy pointers.

Allocates new C-array and copies pointers to Data objects.

Parameters
otherthe GArray to be copied.

Definition at line 203 of file GArray.h.

References Util::GArray< Data >::isAllocated().

◆ ~GArray()

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

Destructor.

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

Definition at line 226 of file GArray.h.

Member Function Documentation

◆ operator=()

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

Assignment, element by element.

Parameters
otherthe rhs GArray

Definition at line 239 of file GArray.h.

◆ reserve()

template<typename Data >
void Util::GArray< 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 255 of file GArray.h.

References UTIL_THROW.

Referenced by Util::Polynomial< T >::operator*=(), Util::Polynomial< T >::operator=(), and Util::Polynomial< T >::Polynomial().

◆ deallocate()

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

Deallocate (delete) underlying array of pointers.

Sets capacity and size to zero.

Definition at line 286 of file GArray.h.

Referenced by Util::Binomial::clear().

◆ clear()

template<typename Data >
void Util::GArray< Data >::clear

Reset to empty state.

Sets size to zero, but leaves capacity unchanged. Does not call destructor for deleted elements.

Definition at line 299 of file GArray.h.

Referenced by Util::Polynomial< T >::setToZero().

◆ serialize()

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

Serialize a GArray to/from an Archive.

Parameters
ararchive
versionarchive version id

Definition at line 380 of file GArray.h.

◆ begin() [1/2]

template<class Data >
void Util::GArray< Data >::begin ( ArrayIterator< Data > &  iterator)
inline

Set an ArrayIterator to the beginning of this Array.

Parameters
iteratorArrayIterator, initialized on output.

Definition at line 405 of file GArray.h.

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

◆ begin() [2/2]

template<class Data >
void Util::GArray< Data >::begin ( ConstArrayIterator< Data > &  iterator) const
inline

Set a ConstArrayIterator to the beginning of this Array.

Parameters
iteratorConstArrayIterator, initialized on output.

Definition at line 416 of file GArray.h.

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

◆ append()

template<typename Data >
void Util::GArray< Data >::append ( Data const &  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 306 of file GArray.h.

Referenced by Util::Polynomial< T >::operator*=(), Util::Polynomial< T >::operator+=(), Util::Polynomial< T >::operator-=(), Util::Polynomial< T >::operator=(), and Util::Polynomial< T >::Polynomial().

◆ resize()

template<typename Data >
void Util::GArray< Data >::resize ( int  n)

Resizes array so that it contains n elements.

This function changes the size of the array to n, and changes the capacity iff necesary to accomodate the change in size. Upon return, size is set to n. In what follows, "size" and "capacity" refer to values on entry:

If n < size, size is reset, but no destructors are called If n > size, all added elements are value initialized If n > capacity, new memory is allocated and the array is moved

Parameters
ndesired number of elements

Definition at line 339 of file GArray.h.

References UTIL_THROW.

Referenced by Util::Binomial::setup().

◆ operator[]() [1/2]

template<class Data >
Data & Util::GArray< Data >::operator[] ( int  i)
inline

Mimic C array subscripting.

Parameters
iarray index
Returns
reference to element i

Definition at line 426 of file GArray.h.

◆ operator[]() [2/2]

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

Mimic C array subscripting.

Parameters
iarray index
Returns
const reference to element i

Definition at line 437 of file GArray.h.

◆ capacity()

template<class Data >
int Util::GArray< Data >::capacity
inline

Return physical capacity of array.

Definition at line 448 of file GArray.h.

Referenced by Util::Binomial::clear().

◆ size()

template<class Data >
int Util::GArray< Data >::size
inline

◆ isAllocated()

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

Is this array allocated?

Definition at line 462 of file GArray.h.

Referenced by Util::GArray< Data >::GArray().


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