NAME
OTC_Queue -
Implements a FIFO or queue.
SYNOPSIS
#include <OTC/collctn/queue.hh>
template<class T>
class OTC_Queue
{
public:
static os_typespec* get_os_typespec();
inline ~OTC_Queue();
OTC_Queue();
OTC_Queue(OTC_Queue<T> const& theQueue);
OTC_Queue<T>& operator=(OTC_Queue<T> const& theQueue);
inline OTC_Boolean isEmpty() const;
inline u_int count() const;
inline T& head();
inline T const& head() const;
void add(T const& theItem);
T remove();
inline void clear();
void discard(u_int theCount);
};
CLASS TYPE
Concrete
DESCRIPTION
OTC_Queue implements a FIFO or queue. 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_Queue();
OTC_Queue(OTC_Queue<T> const& theQueue);
Creates a queue which is a copy of
theQueue. If the queue is holding
pointers, only the value of the pointer
is copied and not the object being
pointed at.
ASSIGNMENT
OTC_Queue<T>& operator=(OTC_Queue<T> const& theQueue);
Replaces this queue with a copy of
theQueue. If the queue is holding
pointers, only the value of the pointer
is copied and not the object being
pointed at.
QUERY
inline OTC_Boolean isEmpty() const;
Returns OTCLIB_TRUE if the queue is empty.
inline u_int count() const;
Returns the number of items in
the queue.
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.
MODIFICATION
void add(T const& theItem);
Adds theItem onto the tail of the
queue.
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();
Clears the queue of all items held.
void discard(u_int theCount);
Discards the first theCount items
on the queue. If there are not that
many items on the queue, an exception
is raised.
NOTES
To allow any number of items to be placed into the queue, 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_BoundedQueue may
be more appropriate.
SEE ALSO
OTC_BoundedQueue
LIBRARY
OTC
AUTHOR(S)
Graham Dumpleton
COPYRIGHT
Copyright 1992 1993 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED