StuBS
|
This class implements a simple, singly-linked list of objects implementing the base class Queue::Node. More...
#include <object/queue.h>
Classes | |
class | Iterator |
A Queue Iterator. More... | |
class | Node |
Base class Node for all queueable classes. More... | |
Public Member Functions | |
Queue () | |
Default constructor; initialized the queue as empty. | |
void | enqueue (T *item) |
Enqueues the provided item at the end of the queue. | |
T * | dequeue () |
Removes the first element in the queue and returns it. | |
Iterator | begin () |
Iterator | end () |
T * | remove (T *item, bool(*cmp)(T *, T *)=[](T *a, T *b) {return a==b;}) |
Removes and returns a single element from the queue. | |
void | insertFirst (T *item) |
Adds item to the beginning of the queue. | |
void | insertAfter (T *old_item, T *new_item) |
Inserts the element new_item directly after old_item . | |
T * | first () |
Returns the first element in the queue without removing it. | |
T * | next (T *o) |
Returns the next element in the queue for a given element. | |
Private Member Functions | |
Queue (const Queue< T, ContainerType > &)=delete | |
Queue & | operator= (const Queue< T, ContainerType > &)=delete |
Private Attributes | |
ContainerType< T * > | head |
ContainerType< T ** > | tail |
This class implements a simple, singly-linked list of objects implementing the base class Queue::Node.
Queue::Node itself merely adds an attribute _next_node
to the parent object, allowing to enqueue the element into a single Queue.
The following example illustrates the usage of Queue::Node :
class Foo : public Queue<Foo>::Node { // ... }
This Queue implementation supports using C++11 range expressions:
Queue<Foo> list; Foo a, b, c; list.enqueue(&a); list.enqueue(&b); list.enqueue(&c); for(Foo * elem : list) { // use elem }
|
privatedelete |
|
inline |
Default constructor; initialized the queue as empty.
|
privatedelete |
|
inline |
Enqueues the provided item at the end of the queue.
item | Queue element to be appended. |
|
inline |
Removes the first element in the queue and returns it.
nullptr
if the queue was empty.
|
inline |
Returns an iterator referring to the head of the queue.
|
inline |
Returns an end iterator.
|
inline |
Removes and returns a single element from the queue.
This method removes and returns a single element (provided via parameter item
) from the queue, irrespective of its position. By default, this function compares pointers; it is possible to override the default comparator lambda function by specifying a function type as second parameter.
item | Element to be removed. |
cmp | Comparator function. |
0
if no element matches.
|
inline |
Adds item
to the beginning of the queue.
item | The element to be inserted. |
Inserts the element new_item
directly after old_item
.
old_item | Element to insert after. |
new_item | Element to be inserted. |
|
inline |
Returns the first element in the queue without removing it.
|
inline |
Returns the next element in the queue for a given element.
|
private |
|
private |