NAME

OTC_BoundedStack - Implements a LIFO or stack with fixed capacity.

SYNOPSIS


#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);
};

CLASS TYPE

Concrete

DESCRIPTION

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.

INITIALISATION

OTC_BoundedStack(u_int theCapacity, T* theMem=0);
OTC_BoundedStack(OTC_BoundedStack<T> const& theStack);

ASSIGNMENT

OTC_BoundedStack<T>& operator=(OTC_BoundedStack<T> const& theStack);

QUERY

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;

MODIFICATION

inline void push(T const& theItem);
inline T pop();
inline void clear();
inline void discard(u_int theCount);

NOTES

Being a bounded stack, for efficiency, an array is used in the internal implementation instead of a linked list. The consequences are, that when parameterised over a class type, the class must have a constructor which accepts no arguments and also be capable of having assignment performed upon it.

LIBRARY

OTC

AUTHOR(S)

Graham Dumpleton

COPYRIGHT

Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED