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

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.

#include <GStack.h>

Public Member Functions

 GStack ()
 Constructor. More...
 
 GStack (const GStack< Data > &other)
 Copy constructor, copy pointers. More...
 
 ~GStack ()
 Destructor. More...
 
GStack< Data > & operator= (const GStack< Data > &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...
 
const Data & 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...
 

Constructor & Destructor Documentation

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

Constructor.

Definition at line 157 of file GStack.h.

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

Copy constructor, copy pointers.

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

Parameters
otherthe GStack to be copied.

Allocates a new Data* array and copies all pointer values.

Parameters
otherthe GStack to be copied.

Definition at line 171 of file GStack.h.

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 208 of file GStack.h.

References Util::Memory::deallocate(), and Util::GStack< Data >::isAllocated().

Member Function Documentation

template<typename Data>
GStack< Data > & Util::GStack< Data >::operator= ( const GStack< Data > &  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 221 of file GStack.h.

References Util::GStack< Data >::clear().

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 237 of file GStack.h.

References Util::GStack< Data >::capacity(), and UTIL_THROW.

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

Deallocate (delete) underlying array of pointers.

Definition at line 277 of file GStack.h.

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

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

Reset to empty state.

Definition at line 291 of file GStack.h.

Referenced by Util::GStack< Data >::operator=().

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 298 of file GStack.h.

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

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 340 of file GStack.h.

References UTIL_THROW.

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

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

Definition at line 355 of file GStack.h.

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

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

Definition at line 362 of file GStack.h.

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

Return allocated size.

Returns
Number of elements allocated in array.

Definition at line 369 of file GStack.h.

Referenced by Util::GStack< Data >::reserve().

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

Return logical size.

Returns
logical size of this array.

Definition at line 376 of file GStack.h.

template<class Data >
bool Util::GStack< Data >::isAllocated ( ) const
inline

Is this GStack allocated?

Definition at line 383 of file GStack.h.

Referenced by Util::GStack< Data >::deallocate(), Util::GStack< Data >::push(), and Util::GStack< Data >::~GStack().

template<typename Data >
bool Util::GStack< Data >::isValid ( ) const

Is this GStack in a valid internal state?

Definition at line 390 of file GStack.h.

References UTIL_THROW.


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