StuBS
|
Templated Queue for arbitrary objects. More...
#include <queue.h>
Classes | |
class | Iterator |
Minimal forward iterator You can use this iterator to iterate the queue like a normal STL container. It only supports forward iteration, since the queue is single linked. More... | |
Public Member Functions | |
Queue (NextFunc get_link=default_get_link) | |
Constructor. More... | |
bool | enqueue (T &item) |
Enqueues the provided item at the end of the queue. If the element is already contained in the queue, false will be returned. More... | |
bool | insertFirst (T &item) |
insert a new element at the start of the queue More... | |
bool | insertAfter (T &after, T &item) |
Insert a new element item into the list after an element after. Returns false if item is already in the/a list or after is not in this list. More... | |
T * | next (T &item) |
return the next element of a given one or nullptr if the end is reached More... | |
bool | is_empty () |
Return whether or not the queue is empty. More... | |
T * | dequeue () |
Removes the first element in the queue and returns it. More... | |
T * | remove (T *that) |
Removes a given element from the queue and returns that element, or nullptr if it was not present. More... | |
Queue< T >::Iterator | begin () |
get an iterator to the first element | |
Queue< T >::Iterator | end () |
get an iterator that marks the end of list | |
T * | first () |
get the first element of the queue | |
T * | last () |
get the last element of the queue | |
Private Types | |
typedef T **(* | NextFunc) (T &) |
Type definition for the get_link function. | |
Static Private Member Functions | |
static T ** | default_get_link (T &obj) |
Default get_link implementation returns a pointer to the next-pointer. | |
Private Attributes | |
const NextFunc | get_link |
T * | head |
T * | tail |
Templated Queue for arbitrary objects.
Queue is implemented by a head-object (Queue<T>) and next-pointers embedded in the queued objects. By passing a different get_link function into the constructor, the member name of the next-pointer can be changed and objects can be contained in different independent queues.
|
inlineexplicit |
Constructor.
[in] | get_link | A function pointer to the get_link, i.e. a function which returns a pointer to the next-pointer of an element in the Queue. |
|
inline |
Removes the first element in the queue and returns it.
nullptr
if the queue was empty.
|
inline |
Enqueues the provided item at the end of the queue. If the element is already contained in the queue, false will be returned.
[in] | item | element to be appended (enqueued). |
|
inline |
Insert a new element item into the list after an element after. Returns false if item is already in the/a list or after is not in this list.
[in] | after | the element after which the new one should be inserted |
[in] | item | the new element to add |
|
inline |
insert a new element at the start of the queue
[in] | item | the new item to add |
|
inline |
Return whether or not the queue is empty.
|
inline |
return the next element of a given one or nullptr if the end is reached
[in] | item | the current item |
|
inline |
Removes a given element from the queue and returns that element, or nullptr if it was not present.
Function pointer to the get_link function, called whenever the next pointer array is referenced
|
private |
head points to the first element (the one returned on first dequeue). Can be nullptr if the queue is empty.
|
private |
tail points to the last element (the one last added). Is only valid if head != nullptr