NAME
OTC_Stack -
Implements a LIFO or stack.
SYNOPSIS
#include <OTC/collctn/stack.hh>
template<class T>
class OTC_Stack
{
public:
static os_typespec* get_os_typespec();
inline ~OTC_Stack();
OTC_Stack();
OTC_Stack(OTC_Stack<T> const& theStack);
OTC_Stack<T>& operator=(OTC_Stack<T> const& theStack);
inline OTC_Boolean isEmpty() const;
inline u_int count() const;
inline T& top();
inline T const& top() const;
void push(T const& theItem);
T pop();
inline void clear();
void discard(u_int theCount);
};
CLASS TYPE
Concrete
DESCRIPTION
OTC_Stack implements a LIFO or stack. Note, that it is the
user's responsibility to deal with deletion of objects held in the
stack, when it is parameterised over a pointer type; ie., this
class works independently of the OTC_BaseActions class.
INITIALISATION
OTC_Stack();
OTC_Stack(OTC_Stack<T> const& theStack);
Creates a stack which is a copy of
theStack. If the stack holds pointers,
only the value of the pointers is copied,
not what the pointer points at.
ASSIGNMENT
OTC_Stack<T>& operator=(OTC_Stack<T> const& theStack);
Replaces this stack with a copy of
theStack. If the stack holds pointers,
only the value of the pointers is copied,
not what the pointer points at.
QUERY
inline OTC_Boolean isEmpty() const;
Returns OTCLIB_TRUE if the stack is
empty.
inline u_int count() const;
Returns the number of items held in the
stack.
inline T& top();
Returns a reference to the top item on
the stack. If the stack is empty, an
exception is raised.
inline T const& top() const;
Returns a reference to the top item on
the stack. If the stack is empty, an
exception is raised.
MODIFICATION
void push(T const& theItem);
Pushes theItem onto the top of
the stack.
T pop();
Removes the top item off the stack and
returns it. If the stack is empty, an
exception is raised.
inline void clear();
Clears the stack of all items.
void discard(u_int theCount);
Discards the top theCount items on the
stack. If there are not that many items on
the stack, an exception is raised.
NOTES
To allow any number of items to be placed into the stack, it is
implemented using a linked list. If efficiency is a concern, both
in terms of speed and memory use, and there is a fixed upper bound
on the number of items to be held, the class OTC_BoundedStack may
be more appropriate.
SEE ALSO
OTC_BoundedStack
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED