semf
semf::LinkedQueue< T > Class Template Reference

LinkedQueue is an managed single linked queue implementation. More...

#include <linkedqueue.h>

Collaboration diagram for semf::LinkedQueue< T >:
Collaboration graph

Classes

class  ConstIterator
 Implementation of a forward constant iterator for LinkedQueue. More...
 
class  Iterator
 Implementation of a forward iterator for LinkedQueue. More...
 
class  Node
 Implements the next() functionality for every element in a queue. More...
 

Public Member Functions

T & front ()
 Returns a reference to the first element in the queue. More...
 
const T & front () const
 Returns a reference to the first element in the queue. More...
 
T & back ()
 Returns a reference to the last element in the queue. More...
 
const T & back () const
 Returns a reference to the last element in the queue. More...
 
Iterator begin ()
 Returns an iterator pointing to the first element in the queue. More...
 
ConstIterator begin () const
 Returns an iterator pointing to the first element in the queue. More...
 
ConstIterator cbegin () const
 Returns an iterator pointing to the first element in the queue. More...
 
Iterator end ()
 Returns an iterator referring to the past-the-end element in the queue. More...
 
ConstIterator end () const
 Returns an iterator referring to the past-the-end element in the queue. More...
 
ConstIterator cend () const
 Returns an iterator referring to the past-the-end element in the queue. More...
 
bool empty () const
 Returns whether the queue is empty (i.e. whether its size is 0). More...
 
size_t size () const
 Returns the number of elements in the queue. More...
 
void push (T &element)
 Adds a new element to the end of the queue, after its current last element. More...
 
void pop ()
 Removes the first element in the queue, effectively reducing the queue size by one. More...
 
LinkedQueue< T > & operator= (const LinkedQueue< T > &queue)
 Assigns new contents to the queue, replacing its current contents, and modifying its size accordingly. More...
 

Detailed Description

template<class T>
class semf::LinkedQueue< T >

LinkedQueue is an managed single linked queue implementation.

It is similar to std::queue, but works without dynamic storage allocation. Every element in the queue has to inherit from LinkedQueue::Node and in case has the information of the next() node.

The LinkedQueue class is a list that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data organization.

Attention
A node is only allowed to be part of one queue. Putting a node into a second queue changes the reference in the element. That causes to undefined behavior by iterating through the queues.
Template Parameters
Tclass type inherits from LinkedQueue::Node

Definition at line 37 of file linkedqueue.h.

Member Function Documentation

◆ back() [1/2]

template<class T >
T & semf::LinkedQueue< T >::back

Returns a reference to the last element in the queue.

This is the most recently pushed element. Calling this function on a not existing element causes undefined behavior.

Returns
Reference to the last element.

Definition at line 423 of file linkedqueue.h.

◆ back() [2/2]

template<class T >
const T & semf::LinkedQueue< T >::back

Returns a reference to the last element in the queue.

This is the most recently pushed element. Calling this function on a not existing element causes undefined behavior.

Returns
For a const-qualified queue object returns a const reference to the last element.

Definition at line 429 of file linkedqueue.h.

◆ begin() [1/2]

template<class T >
LinkedQueue< T >::Iterator semf::LinkedQueue< T >::begin

Returns an iterator pointing to the first element in the queue.

Attention
Notice that, unlike member LinkedQueue::front, which returns a reference to the first element, this function returns a forward iterator pointing to it. If the queue is empty, the returned iterator value shall not be dereferenced.
Returns
An iterator to the beginning of the sequence.

Definition at line 435 of file linkedqueue.h.

Here is the caller graph for this function:

◆ begin() [2/2]

template<class T >
LinkedQueue< T >::ConstIterator semf::LinkedQueue< T >::begin

Returns an iterator pointing to the first element in the queue.

Attention
Notice that, unlike member LinkedQueue::front, which returns a reference to the first element, this function returns a forward iterator pointing to it. If the queue is empty, the returned iterator value shall not be dereferenced.
Returns
An iterator to the beginning of the sequence.

Definition at line 441 of file linkedqueue.h.

◆ cbegin()

template<class T >
LinkedQueue< T >::ConstIterator semf::LinkedQueue< T >::cbegin

Returns an iterator pointing to the first element in the queue.

Attention
Notice that, unlike member LinkedQueue::front, which returns a reference to the first element, this function returns a forward iterator pointing to it. If the queue is empty, the returned iterator value shall not be dereferenced.
Returns
An iterator to the beginning of the sequence.

Definition at line 447 of file linkedqueue.h.

◆ cend()

template<class T >
LinkedQueue< T >::ConstIterator semf::LinkedQueue< T >::cend

Returns an iterator referring to the past-the-end element in the queue.

The past-the-end element is the theoretical element that would follow the last element in the queue. It does not point to any element, and thus shall not be dereferenced. This function is often used in combination with LinkedQueue::begin to specify a range including all the elements in the range. If LinkedQueue is empty, this function returns the same as LinkedQueue::begin.

Returns
An iterator to the element past the end of the sequence.

Definition at line 465 of file linkedqueue.h.

◆ empty()

template<class T >
bool semf::LinkedQueue< T >::empty

Returns whether the queue is empty (i.e. whether its size is 0).

This function does not modify the queue in any way.

Returns
true if the queue size is 0, false otherwise.

Definition at line 471 of file linkedqueue.h.

◆ end() [1/2]

template<class T >
LinkedQueue< T >::Iterator semf::LinkedQueue< T >::end

Returns an iterator referring to the past-the-end element in the queue.

The past-the-end element is the theoretical element that would follow the last element in the queue. It does not point to any element, and thus shall not be dereferenced. This function is often used in combination with LinkedQueue::begin to specify a range including all the elements in the range. If LinkedQueue is empty, this function returns the same as LinkedQueue::begin.

Returns
An iterator to the element past the end of the sequence.

Definition at line 453 of file linkedqueue.h.

Here is the caller graph for this function:

◆ end() [2/2]

template<class T >
LinkedQueue< T >::ConstIterator semf::LinkedQueue< T >::end

Returns an iterator referring to the past-the-end element in the queue.

The past-the-end element is the theoretical element that would follow the last element in the queue. It does not point to any element, and thus shall not be dereferenced. This function is often used in combination with LinkedQueue::begin to specify a range including all the elements in the range. If LinkedQueue is empty, this function returns the same as LinkedQueue::begin.

Returns
An iterator to the element past the end of the sequence.

Definition at line 459 of file linkedqueue.h.

◆ front() [1/2]

template<class T >
T & semf::LinkedQueue< T >::front

Returns a reference to the first element in the queue.

This element will be the first element to be removed on a call to pop(). Calling this function on a not existing element causes undefined behavior.

Returns
Reference to the first element.

Definition at line 411 of file linkedqueue.h.

◆ front() [2/2]

template<class T >
const T & semf::LinkedQueue< T >::front

Returns a reference to the first element in the queue.

This element will be the first element to be removed on a call to pop(). Calling this function on a not existing element causes undefined behavior.

Returns
For a const-qualified queue object returns a const reference to the first element.

Definition at line 417 of file linkedqueue.h.

◆ operator=()

template<class T >
LinkedQueue< T > & semf::LinkedQueue< T >::operator= ( const LinkedQueue< T > &  queue)

Assigns new contents to the queue, replacing its current contents, and modifying its size accordingly.

Parameters
queueA queue object of the same type (i.e., with the same template parameter).
Returns
Reference to this queue.

Definition at line 521 of file linkedqueue.h.

◆ pop()

template<class T >
void semf::LinkedQueue< T >::pop

Removes the first element in the queue, effectively reducing the queue size by one.

Definition at line 505 of file linkedqueue.h.

◆ push()

template<class T >
void semf::LinkedQueue< T >::push ( T &  element)

Adds a new element to the end of the queue, after its current last element.

The content of element is moved into the queue. This effectively increases the queue size by one.

Parameters
elementElement to add to the end of the queue.

Definition at line 483 of file linkedqueue.h.

◆ size()

template<class T >
size_t semf::LinkedQueue< T >::size

Returns the number of elements in the queue.

Returns
Number of elements in the queue.

Definition at line 477 of file linkedqueue.h.