|
Simpatico
v1.10
|
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.
#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... | |
|
inline |
| Util::GStack< Data >::GStack | ( | const GStack< Data > & | other | ) |
| 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().
| GStack< Data > & Util::GStack< Data >::operator= | ( | const GStack< Data > & | 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 237 of file GStack.h.
References Util::GStack< Data >::capacity(), and UTIL_THROW.
| void Util::GStack< Data >::deallocate | ( | ) |
Deallocate (delete) underlying array of pointers.
Definition at line 277 of file GStack.h.
References Util::GStack< Data >::isAllocated().
|
inline |
Reset to empty state.
Definition at line 291 of file GStack.h.
Referenced by Util::GStack< Data >::operator=().
| 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 298 of file GStack.h.
References Util::GStack< Data >::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 340 of file GStack.h.
References UTIL_THROW.
|
inline |
|
inline |
|
inline |
Return allocated size.
Definition at line 369 of file GStack.h.
Referenced by Util::GStack< Data >::reserve().
|
inline |
|
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().
| 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.
1.8.11