NAME
OTC_BoundedQueue -
Implements a FIFO or queue with fixed capacity.
SYNOPSIS
#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);
};
CLASS TYPE
Concrete
DESCRIPTION
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.
INITIALISATION
OTC_BoundedQueue(u_int theCapacity, T* theMem=0);
Creates an empty queue which has
capacity to hold 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);
Creates a queue which is a copy of
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.
ASSIGNMENT
OTC_BoundedQueue<T>& operator=(OTC_BoundedQueue<T> const& theQueue);
Replaces this queue with the contents of
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.
QUERY
inline OTC_Boolean isEmpty() const;
Returns OTCLIB_TRUE if the queue is empty.
inline OTC_Boolean isFull() const;
Returns OTCLIB_TRUE if the queue is full.
inline u_int count() const;
Returns the number of items in the queue.
inline u_int capacity() const;
Returns the maximum number of items which
the queue can hold.
inline T& head();
Returns a reference to the item on
the head of the queue. If the queue
is empty, an exception is raised.
inline T const& head() const;
Returns a reference to the item on
the head of the queue. If the queue
is empty, an exception is raised.
inline T& peek(u_int theIndex);
Returns the item in the queue given by
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;
Returns the item in the queue given by
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.
MODIFICATION
void add(T const& theItem);
Adds theItem onto the tail of the
queue. If the capacity of the queue would
be exceeded, an exception is raised.
T remove();
Removes and returns the item at
the head of the queue. If the queue
is empty, an exception is raised.
inline void clear();
void discard(u_int theCount);
Discards the first theCount items
from the head of the queue. If there
are not that many items, an
exception is raised.
NOTES
Being a bounded queue, 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