Queue

class

A pointer based FIFO style Queue.

**Note: You should avoid using this Queue class, and consider its template based counter part: GenericQueue**

This is a basic single linked FIFO queue structure. All items in the queue must implement the QueueItem interface.

In theory you can add different types into the queue, as long as they all inherit QueueItem. However, you should not do this. Mixing different types in the queue, removes type information - such that the objects original type can not be restored later.

Best practice is therefore to use only one type in the queue. To help with this you should really use the GenericQueue class. This class uses C++ templating to keep type information and you do not need to manual type casting.

See
GenericQueue

Public Functions

Queue::Queue()

Construct an empty queue.

void mono::Queue::enqueue(IQueueItem *item)

Add a new element to the back of the queue Insert a pointer to an element on the back of the queue.

IQueueItem *mono::Queue::dequeue()

Returns and removes the oldest element in the queue.

IQueueItem *mono::Queue::peek()

Return the oldest element in the queue, without removing it.

IQueueItem *mono::Queue::next(IQueueItem *item)

Get the next element in the queue, after the one you provide.

NOTE: There is no check if the item belongs in the parent queue at all!

Return
The next element in the queue, after the item you provided.
Parameters
  • item -

    A pointer to an item in the queue

bool mono::Queue::exists(IQueueItem *item)

Check that an object already exists in the queue. Because of the stack based nature of this queue, all objects can only exist one replace in the queue. You cannot add the same object to two different positions in the queue.

Parameters
  • item -

    The element to search for in the queue

uint16_t Queue::Length()

Return the length of the queue.

The length is the number of item currently present in the queue.

This method runs in O(n) (linear time)