#include <OTC/collctn/bndqueue.hh> template<class T> class OTC_BoundedQueue {
public:
static os_typespec* get_os_typespec();
~OTC_BoundedQueue();
OTC_BoundedQueue(u_int theCapacity, T* theMem=0);
OTC_BoundedQueue(OTC_BoundedQueue<T> const& theQueue);
OTC_BoundedQueue<T>& operator=( OTC_BoundedQueue<T> const& theQueue );
inline OTC_Boolean isEmpty() const;
inline OTC_Boolean isFull() const;
inline u_int count() const;
inline u_int capacity() const;
inline T& head();
inline T const& head() const;
inline T& peek(u_int theIndex);
inline T const& peek(u_int theIndex) const;
void add(T const& theItem);
T remove();
inline void clear();
void discard(u_int theCount);
};
OTC_BoundedQueue
implements a FIFO or queue with fixed capacity.
Note, that it is the user's responsibility to deal with deletion
of objects held in the queue when it is parameterised over a
pointer type; ie., this class works independently of the
OTC_BaseActions
class.
OTC_BoundedQueue(u_int theCapacity, T* theMem=0);
theCapacity
items.
If memory is provided through theMem
it will be used, else memory will
be allocated from the free store. If
the memory is provided by the user, it
is the user's responsibility to delete
it.
OTC_BoundedQueue(OTC_BoundedQueue<T> const& theQueue);
theQueue
. Space required by this queue
will always be allocated from the free
store. If pointers are held in the queue,
only the value of the pointers is copied,
not what the pointer is pointing at.
OTC_BoundedQueue<T>& operator=(OTC_BoundedQueue<T> const& theQueue);
theQueue
. Space required by this queue
will always be allocated from the free
store. The capacity of this queue will
be changed to that of theQueue
.
If pointers are held in the queue,
only the value of the pointers is copied,
not what the pointers point at.
inline OTC_Boolean isEmpty() const;
OTCLIB_TRUE
if the queue is empty.
inline OTC_Boolean isFull() const;
OTCLIB_TRUE
if the queue is full.
inline u_int count() const;
inline u_int capacity() const;
inline T& head();
inline T const& head() const;
inline T& peek(u_int theIndex);
theIndex
. An index of 0
represents the
head of the queue. Successive items are
numbered from 1
onwards. If
theIndex
is outside the bounds of the
queue, an exception is raised.
inline T const& peek(u_int theIndex) const;
theIndex
. An index of 0
represents the
head of the queue. Successive items are
numbered from 1
onwards. If
theIndex
is outside the bounds of the
queue, an exception is raised.
void add(T const& theItem);
theItem
onto the tail of the
queue. If the capacity of the queue would
be exceeded, an exception is raised.
T remove();
inline void clear();
void discard(u_int theCount);
theCount
items
from the head of the queue. If there
are not that many items, an
exception is raised.