Go to the previous, next section.
#include <nihcl/Stack.h>
Class
Stack
implements a variable-depth stack of pointers to objects. Object pointers can be pushed and popped from the top of a
Stack
via member functions
push()
and
pop()
, and the current top of the stack can be accessed via the member function
top()
or at index 0. Pointers further down the stack can be accessed at higher indices.
Stack(unsigned
capacity
=DEFAULT_CAPACITY)
Stack
that can hold up to
capacity
objects. An
NIHCL_ALLOCSIZE
error is raised if
capacity
is not greater than 0. If an attempt is made to add more than
capacity
objects to a
Stack
,
reSize()
is called to increase its capacity.
void push(Object&
ob)
Stack
.
virtual Object* add(Object&
ob)
Stack
and returns a pointer to
ob.
Object* pop()
virtual Object* removeLast()
Stack
and returns a pointer to it. If this
Stack
is empty, an
NIHCL_CLTNEMPTY
error results.
virtual void removeAll()
Stack
.
virtual unsigned hash() const
Set
can use as a hash table probe. Class
Stack
implements
hash()
by exclusinve ORing the results of applying
hash()
to all objects in a
Stack
.
bool operator==(const Stack&) const
bool operator!=(const Stack&) const
YES
if the left
Stack
operand is equal to (or not equal to) the right
Stack
operand.
virtual bool isEmpty() const
YES
if this
Stack
contains no objects.
virtual void deepenShallowCopy()
deepCopy()
to all the object pointers, replacing each pointer with a pointer to its copy.
Object*& operator[](int
i)
const Object *const& operator[](int
i) const
virtual Object*& at(int
i)
virtual const Object *const& at(int
i) const
Stack
. Index 0 accesses the top of the
Stack
. These functions perform a range check on the index
i
and raise an
NIHCL_INDEXRANGE
error if
i
is out of bounds.
Object* top() const
virtual Object* last() const
Stack
. If this
Stack
is empty, an
NIHCL_CLTNEMPTY
exception results.
virtual unsigned capacity() const
Stack
can hold before it will need to be expanded.
virtual unsigned size() const
Stack
.
virtual void reSize(unsigned
newSize)
Stack
to
newSize. If
newSize
is less than or equal to
size(), then the capacity is not changed.
virtual void storer(OIOofd&
fd) const
virtual void storer(OIOout&
strm) const
storeOn()
to each of the objects contained in this
Stack
to store them on
fd
or
strm.
virtual void atAllPut(Object&
ob)
virtual int indexOfSubCollection(const SeqCltn&
cltn, int
start
=0) const
virtual Object* remove(const Object&
ob)
shouldNotImplement()
.
Go to the previous, next section.