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

An automatically growable Stack. More...

#include <GStack.h>

Public Member Functions

 GStack ()
 Constructor. More...
 
 GStack (GStack< Data > const &other)
 Copy constructor, copy pointers. More...
 
 ~GStack ()
 Destructor. More...
 
GStack< Data > & operator= (GStack< Data > const &other)
 Assignment, element by element. 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...
 
void push (Data &data)
 Push an element onto the stack. More...
 
Data & pop ()
 Pop an element off the stack. More...
 
Data & peek ()
 Return a reference to the top element (don't pop). More...
 
Data const & peek () const
 Return a const ref to the top element (don't pop). More...
 
int capacity () const
 Return allocated size. More...
 
int size () const
 Return logical size. More...
 
bool isAllocated () const
 Is this GStack allocated? More...
 
bool isValid () const
 Is this GStack in a valid internal state? More...
 

Detailed Description

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

An automatically growable Stack.

A GStack is stack that is implemented as a growable pointer array. Like any pointer array it holds pointers to objects, rather than objects, and associated objects are not destroyed when the container is deallocated or destroyed.

Definition at line 28 of file GStack.h.

Constructor & Destructor Documentation

◆ GStack() [1/2]

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

Constructor.

Definition at line 157 of file GStack.h.

◆ GStack() [2/2]

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

Copy constructor, copy pointers.

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

Parameters
otherthe GStack to be copied.

Definition at line 169 of file GStack.h.

◆ ~GStack()

template<typename Data >
Util::GStack< Data >::~GStack

Destructor.

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

Definition at line 206 of file GStack.h.

References Util::Memory::deallocate().

Member Function Documentation

◆ operator=()

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

Assignment, element by element.

Preconditions:

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

Definition at line 219 of file GStack.h.

◆ reserve()

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

References UTIL_THROW.

◆ deallocate()

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

Deallocate (delete) underlying array of pointers.

Definition at line 275 of file GStack.h.

◆ clear()

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

Reset to empty state.

Definition at line 289 of file GStack.h.

◆ push()

template<typename Data >
void Util::GStack< Data >::push ( Data &  data)

Push an element onto the stack.

Resizes array if space is inadequate.

Parameters
dataelement to be added to stack.

Definition at line 296 of file GStack.h.

◆ pop()

template<typename Data >
Data & Util::GStack< Data >::pop

Pop an element off the stack.

Returns the top element by reference and removes it, decrementing the size by one.

Returns
the top element (which is popped off stack).

Definition at line 338 of file GStack.h.

References UTIL_THROW.

◆ peek() [1/2]

template<typename Data >
Data & Util::GStack< Data >::peek
inline

Return a reference to the top element (don't pop).

Definition at line 353 of file GStack.h.

◆ peek() [2/2]

template<typename Data >
Data const & Util::GStack< Data >::peek
inline

Return a const ref to the top element (don't pop).

Definition at line 360 of file GStack.h.

◆ capacity()

template<typename Data >
int Util::GStack< Data >::capacity
inline

Return allocated size.

Returns
Number of elements allocated in array.

Definition at line 367 of file GStack.h.

◆ size()

template<typename Data >
int Util::GStack< Data >::size
inline

Return logical size.

Returns
logical size of this array.

Definition at line 374 of file GStack.h.

Referenced by pscfpp.file.File::__eq__(), pscfpp.text.Record::__init__(), pscfpp.file.File::__init__(), pscfpp.file.File::__repr__(), and pscfpp.text.Record::__str__().

◆ isAllocated()

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

Is this GStack allocated?

Definition at line 381 of file GStack.h.

◆ isValid()

template<typename Data >
bool Util::GStack< Data >::isValid

Is this GStack in a valid internal state?

Definition at line 388 of file GStack.h.

References UTIL_THROW.


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