The Queue class is a templated container acting as a first in, first out (FIFO) array. It
can be either static or dynamic. Static means it’s allocated once in memory and will not
autoresize. When full it will throw an overflow exception. Dynamic means the container
will autoresize as new items are pushed on the queue. An overflow exception will then
only occure if available memory is exhausted.
Synopsis
#include <lyric/Queue.hpp>
template <class QIT>
class Queue : private List<QIT>
{
public:
~Queue ();
Queue ();
Queue (Size initsize, Size resize = 0)
throw (Exception::Memory::Alloc);
Queue (const Queue& queue)
throw (Exception::Memory::Alloc);
Queue& operator = (const Queue& queue)
throw (Exception::Memory::Alloc);
void create (Size initsize, Size resize = 0)
throw (Exception::Memory::Alloc);
void clean ();
bool empty () const;
void push (const QIT& item)
throw (Exception::Queue::Overflow);
QIT pop ()
throw (Exception::Queue::Underflow);
const QIT& top () const
throw (Exception::Queue::Underflow);
};
Description
-
˜Queue () -
Destroys this queue, releasing eventually reserved memory. All stored items
are destroyed.
-
Queue () -
Constucts this queue as dynamic queue with a resize size of 1.
-
Queue (Size initsize, Size resize = 0) -
Constructs this queue with a starting memory size initsize and a given resize
factor. If resize is zero (or not set), the queue is defined static and will not grow
over the given initsize. If resize is greater than zero, the queue will automatically
grow as items are pushed on.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found for the
initial size.
-
Queue (const Queue& queue) -
Constructs this from queue. All properties, content, and status of queue are given
to this.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found for this
to clone queue.
-
Queue& operator = (const Queue& queue) -
Clones queue into this. All properties, content, and status of queue are given to
this.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found for this
to clone queue.
-
void create (Size initsize, Size resize = 0) -
Creates this queue with a starting memory size initsize and a given resize factor. If
resize is zero (or not set), the queue is defined static and will not grow over the
given initsize. If resize is greater than zero, the queue will automatically grow as
items are pushed on.
Warning Create is destructive. It will destroy all items previously stored in
this queue.
-
Exception::Memory::Alloc
- is thrown if not enough memory is found for the
initial size.
-
void clean () -
Cleans the content of this queue. Destroys all stored items and sets queue pointer
to zero.
-
bool empty () const -
Returns true if this queue is empty, false if not.
-
void push (const QIT& item) -
Pushes item on this queue, and increments the queue pointer.
-
Exception::Queue::Overflow
- is thrown if this queue was defined static and
was full, or if the queue was defined dynamic and no more memory is
left on the system to store the extra item.
-
QIT pop () - Pops
the top item from this queue, decrements the queue pointer, and returns the
item.
-
Exception::Queue::Underflow
- is thrown if this queue was empty before the
pop.
-
const QIT& top () const -
Returns the top most item from this queue, without poping it.
-
Exception::Queue::Underflow
- is thrown if this queue is empty.