WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_46.html taken on Sat Jun 10 19:14:02 1995

Go to the previous, next section.

Stack--Stack of Object Pointers

SYNOPSIS

#include <nihcl/Stack.h>

BASE CLASS

SeqCltn

DERIVED CLASSES

None

RELATED CLASSES

Iterator

DESCRIPTION

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.

CONSTRUCTORS

Stack(unsigned capacity =DEFAULT_CAPACITY)
Constructs an empty 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.

ADDING OBJECTS

void push(Object& ob)
Pushes a pointer to object ob on the top of this Stack.

virtual Object* add(Object& ob)
Pushes a pointer to object ob on the top of this Stack and returns a pointer to ob.

REMOVING OBJECTS

Object* pop()
virtual Object* removeLast()
Removes the topmost object from this Stack and returns a pointer to it. If this Stack is empty, an NIHCL_CLTNEMPTY error results.

virtual void removeAll()
Removes all the objects from this Stack.

SEARCHING

virtual unsigned hash() const
Returns a number that classes such as 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.

RELATIONAL OPERATORS

bool operator==(const Stack&) const
bool operator!=(const Stack&) const
Return YES if the left Stack operand is equal to (or not equal to) the right Stack operand.

TESTING STACKS

virtual bool isEmpty() const
Returns YES if this Stack contains no objects.

COPYING STACKS

virtual void deepenShallowCopy()
Converts this shallow copy to a deep copy by applying deepCopy() to all the object pointers, replacing each pointer with a pointer to its copy.

INDEXING STACKS

Object*& operator[](int i)
const Object *const& operator[](int i) const
virtual Object*& at(int i)
virtual const Object *const& at(int i) const
Return a reference to the pointer to the ith object from the top of this 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
Return a pointer to the top object on this Stack. If this Stack is empty, an
NIHCL_CLTNEMPTY exception results.

STACK CAPACITY AND SIZE

virtual unsigned capacity() const
Returns the number of objects that this Stack can hold before it will need to be expanded.

virtual unsigned size() const
Returns the number of objects in this Stack.

virtual void reSize(unsigned newSize)
Changes the capacity of this Stack to newSize. If newSize is less than or equal to size(), then the capacity is not changed.

PROTECTED MEMBERS

Object I/O

virtual void storer(OIOofd& fd) const
virtual void storer(OIOout& strm) const
Apply storeOn() to each of the objects contained in this Stack to store them on fd or strm.

DISABLED MEMBER FUNCTIONS

virtual void atAllPut(Object& ob)
virtual int indexOfSubCollection(const SeqCltn& cltn, int start =0) const
virtual Object* remove(const Object& ob)
@itemx{virtual void replaceFrom(int start, int stop, const SeqCltn& replacement,} @itemx{int startAt =0)} These functions are implemented as shouldNotImplement().

EXCEPTIONS RAISED

None

Go to the previous, next section.