|
PSCF v1.3.3
|
An automatically growable Stack. More...
#include <GStack.h>
Public Member Functions | |
| GStack () | |
| Constructor. | |
| GStack (GStack< Data > const &other) | |
| Copy constructor, copy pointers. | |
| ~GStack () | |
| Destructor. | |
| GStack< Data > & | operator= (GStack< Data > const &other) |
| Assignment, element by element. | |
| 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. | |
| void | push (Data &data) |
| Push an element onto the stack. | |
| Data & | pop () |
| Pop an element off the stack. | |
| Data & | peek () |
| Return a reference to the top element (don't pop). | |
| Data const & | peek () const |
| Return a const ref to the top element (don't pop). | |
| int | capacity () const |
| Return allocated size. | |
| int | size () const |
| Return logical size. | |
| bool | isAllocated () const |
| Is this GStack allocated? | |
| bool | isValid () const |
| Is this GStack in a valid internal state? | |
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.
|
inline |
| Util::GStack< Data >::GStack | ( | GStack< Data > const & | other | ) |
Copy constructor, copy pointers.
Allocates new Data* array and copies pointers to Data objects.
| other | the GStack to be copied. |
Definition at line 169 of file GStack.h.
References Util::Memory::allocate(), and GStack().
| 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(), and isAllocated().
| GStack< Data > & Util::GStack< Data >::operator= | ( | GStack< Data > const & | other | ) |
| 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.
| capacity | number of elements for which to reserve space. |
Definition at line 235 of file GStack.h.
References Util::Memory::allocate(), capacity(), Util::Memory::deallocate(), and UTIL_THROW.
| void Util::GStack< Data >::deallocate | ( | ) |
Deallocate (delete) underlying array of pointers.
Definition at line 275 of file GStack.h.
References Util::Memory::deallocate(), and isAllocated().
|
inline |
| void Util::GStack< Data >::push | ( | Data & | data | ) |
Push an element onto the stack.
Resizes array if space is inadequate.
| data | element to be added to stack. |
Definition at line 296 of file GStack.h.
References Util::Memory::allocate(), Util::Memory::deallocate(), and isAllocated().
| 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.
Definition at line 338 of file GStack.h.
References UTIL_THROW.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| bool Util::GStack< Data >::isValid | ( | ) | const |
Is this GStack in a valid internal state?
Definition at line 388 of file GStack.h.
References UTIL_THROW.