#include <OTC/collctn/bndstack.hh> template<class T> class OTC_BoundedStack {
public:
static os_typespec* get_os_typespec();
~OTC_BoundedStack();
OTC_BoundedStack(u_int theCapacity, T* theMem=0);
OTC_BoundedStack(OTC_BoundedStack<T> const& theStack);
OTC_BoundedStack<T>& operator=( OTC_BoundedStack<T> const& theStack );
inline OTC_Boolean isEmpty() const;
inline OTC_Boolean isFull() const;
inline u_int count() const;
inline u_int capacity() const;
inline T& top();
inline T const& top() const;
inline T& peek(u_int theIndex);
inline T const& peek(u_int theIndex) const;
inline void push(T const& theItem);
inline T pop();
inline void clear();
inline void discard(u_int theCount);
};
OTC_BoundedStack
implements a LIFO or stack with fixed capacity.
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.
OTC_BoundedStack(u_int theCapacity, T* theMem=0);
theCapacity
items.
If a section of memory is provided
through theMem
it will be used,
else memory from the free store will
be allocated. If the memory is provided
by the user, it is the user's responsibility
to delete it.
OTC_BoundedStack(OTC_BoundedStack<T> const& theStack);
theStack
. Space for
this stack will always be allocated from
the free store. If holding pointers, only
the pointers are copied, not what the
pointers point at.
OTC_BoundedStack<T>& operator=(OTC_BoundedStack<T> const& theStack);
theStack
. The capacity of this stack
will be changed to that of theStack
.
Space for this stack will always be
allocated from the free store. If holding
pointers, only the pointers are
copied, not what the pointers point at.
inline OTC_Boolean isEmpty() const;
OTCLIB_TRUE
if the stack is empty.
inline OTC_Boolean isFull() const;
OTCLIB_TRUE
if the stack is full.
inline u_int count() const;
inline u_int capacity() const;
inline T& top();
inline T const& top() const;
inline T& peek(u_int theIndex);
theIndex
.
An index of 0
is the top of the
stack. Items below the top of the
stack are numbered from 1
onwards.
If theIndex
is outside the bounds
of the stack, an exception is
raised.
inline T const& peek(u_int theIndex) const;
theIndex
.
An index of 0
is the top of the
stack. Items below the top of the
stack are numbered from 1
onwards.
If theIndex
is outside the bounds
of the stack, an exception is
raised.
inline void push(T const& theItem);
theItem
onto the top of
the stack. If the capacity of the
stack would be exceeded, an exception
is raised.
inline T pop();
inline void clear();
inline void discard(u_int theCount);
theCount
items in
the stack. If there are not that many
items in the stack, an exception
is raised.