PSCF v1.4.0
Util::GArray< Data > Class Template Reference

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

#include <GArray.h>

Public Member Functions

 GArray ()
 Constructor.
 GArray (GArray< Data > const &other)
 Copy constructor.
GArray< Data > & operator= (GArray< Data > const &other)
 Assignment, element by element.
virtual ~GArray ()
 Destructor.
void reserve (int capacity)
 Reserve memory for specified number of elements.
void deallocate ()
 Deallocate (delete) underlying array of pointers.
void clear ()
 Reset to empty state.
template<class Archive>
void serialize (Archive &ar, const unsigned int version)
 Serialize a GArray to/from an Archive.
void begin (ArrayIterator< Data > &iterator)
 Set an ArrayIterator to the beginning of this Array.
void begin (ConstArrayIterator< Data > &iterator) const
 Set a ConstArrayIterator to the beginning of this Array.
void append (Data const &data)
 Append an element to the end of the sequence.
void resize (int n)
 Resizes array so that it contains n elements.
Data & operator[] (int i)
 Mimic C array subscripting.
Data const & operator[] (int i) const
 Mimic C array subscripting.
int capacity () const
 Return physical capacity of array.
int size () const
 Return logical size of this array (i.e., current number of elements).
bool isAllocated () const
 Is this array allocated?

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 188 of file GArray.h.

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

◆ GArray() [2/2]

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

Copy constructor.

Performs a deep copy.

Parameters
otherthe GArray to be copied

Definition at line 200 of file GArray.h.

References Util::Memory::allocate(), GArray(), and isAllocated().

◆ ~GArray()

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

Destructor.

Definition at line 223 of file GArray.h.

References Util::Memory::deallocate(), and isAllocated().

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 236 of file GArray.h.

References append(), clear(), and GArray().

◆ 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 greater than the current capacity. Does nothing if requested capacity is less than current capacity.

Parameters
capacitynumber of elements for which to reserve space

Definition at line 252 of file GArray.h.

References Util::Memory::allocate(), capacity(), Util::Memory::deallocate(), isAllocated(), and UTIL_THROW.

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

◆ deallocate()

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

Deallocate (delete) underlying array of pointers.

Sets capacity and size to zero.

Definition at line 283 of file GArray.h.

References Util::Memory::deallocate(), and isAllocated().

◆ 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 296 of file GArray.h.

Referenced by Pscf::Sort::findBunches(), operator=(), Util::Polynomial< T >::setToZero(), and Pscf::Prdc::sortWaves().

◆ serialize()

template<typename 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 375 of file GArray.h.

References capacity(), reserve(), and size().

◆ begin() [1/2]

template<typename 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 400 of file GArray.h.

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

◆ begin() [2/2]

template<typename 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 411 of file GArray.h.

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

◆ append()

◆ 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 336 of file GArray.h.

References Util::Memory::allocate(), Util::Memory::deallocate(), and UTIL_CHECK.

◆ operator[]() [1/2]

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

Mimic C array subscripting.

Parameters
iarray index
Returns
reference to element i

Definition at line 421 of file GArray.h.

◆ operator[]() [2/2]

template<typename 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 432 of file GArray.h.

◆ capacity()

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

Return physical capacity of array.

Definition at line 443 of file GArray.h.

Referenced by reserve(), and serialize().

◆ size()

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

◆ isAllocated()

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

Is this array allocated?

Definition at line 457 of file GArray.h.

Referenced by deallocate(), GArray(), reserve(), and ~GArray().


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