Nvwa  1.1
Public Member Functions | List of all members
nvwa::fc_queue< _Tp, _Alloc > Class Template Reference

Class to represent a fixed-capacity queue. More...

#include <fc_queue.h>

Public Member Functions

 fc_queue (size_type max_size, const allocator_type &alloc=allocator_type())
 Constructor that creates the queue with a maximum size (capacity). More...
 
 fc_queue (const fc_queue &rhs)
 Copy-constructor that copies all elements from another queue. More...
 
 ~fc_queue ()
 Destructor. More...
 
fc_queueoperator= (const fc_queue &rhs)
 Assignment operator that copies all elements from another queue. More...
 
bool empty () const noexcept
 Checks whether the queue is empty (containing no elements). More...
 
bool full () const noexcept
 Checks whether the queue is full (containing the maximum allowed elements). More...
 
size_type capacity () const noexcept
 Gets the maximum number of allowed elements in the queue. More...
 
size_type size () const noexcept
 Gets the number of existing elements in the queue. More...
 
reference front ()
 Gets the first element in the queue. More...
 
const_reference front () const
 Gets the first element in the queue. More...
 
reference back ()
 Gets the last element in the queue. More...
 
const_reference back () const
 Gets the last element in the queue. More...
 
void push (const value_type &value)
 Inserts a new element at the end of the queue. More...
 
void pop ()
 Discards the first element in the queue. More...
 
bool contains (const value_type &value) const
 Checks whether the queue contains a specific element. More...
 
void swap (fc_queue &rhs)
 Exchanges the elements of two queues. More...
 
allocator_type get_allocator () const
 Gets the allocator of the queue. More...
 

Detailed Description

template<class _Tp, class _Alloc = std::allocator<_Tp>>
class nvwa::fc_queue< _Tp, _Alloc >

Class to represent a fixed-capacity queue.

This class has an interface close to std::queue, but it allows very efficient and lockless one-producer, one-consumer access, as long as the producer does not try to queue an element when the queue is already full.

Parameters
_Tpthe type of elements in the queue
_Allocallocator to use for memory management
Precondition
_Tp shall be CopyConstructible and Destructible, and _Alloc shall meet the allocator requirements (Table 28 in the C++11 spec).

Constructor & Destructor Documentation

◆ fc_queue() [1/2]

template<class _Tp, class _Alloc = std::allocator<_Tp>>
nvwa::fc_queue< _Tp, _Alloc >::fc_queue ( size_type  max_size,
const allocator_type &  alloc = allocator_type() 
)
inlineexplicit

Constructor that creates the queue with a maximum size (capacity).

Parameters
max_sizethe maximum size allowed
allocthe allocator to use
Precondition
max_size shall be not be zero.
Postcondition
Unless memory allocation throws an exception, this queue will be constructed with the specified maximum size, and the following conditions will hold:

◆ fc_queue() [2/2]

template<class _Tp , class _Alloc >
nvwa::fc_queue< _Tp, _Alloc >::fc_queue ( const fc_queue< _Tp, _Alloc > &  rhs)

Copy-constructor that copies all elements from another queue.

Parameters
rhsthe queue to copy
Postcondition
If copy-construction is successful (no exception is thrown during memory allocation and element copy), this queue will have the same elements as rhs.

◆ ~fc_queue()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
nvwa::fc_queue< _Tp, _Alloc >::~fc_queue ( )
inline

Destructor.

It erases all elements and frees memory.

Member Function Documentation

◆ back() [1/2]

template<class _Tp, class _Alloc = std::allocator<_Tp>>
reference nvwa::fc_queue< _Tp, _Alloc >::back ( )
inline

Gets the last element in the queue.

Returns
reference to the last element

◆ back() [2/2]

template<class _Tp, class _Alloc = std::allocator<_Tp>>
const_reference nvwa::fc_queue< _Tp, _Alloc >::back ( ) const
inline

Gets the last element in the queue.

Returns
const reference to the last element

◆ capacity()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
size_type nvwa::fc_queue< _Tp, _Alloc >::capacity ( ) const
inlinenoexcept

Gets the maximum number of allowed elements in the queue.

Returns
the maximum number of allowed elements in the queue

◆ contains()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
bool nvwa::fc_queue< _Tp, _Alloc >::contains ( const value_type &  value) const
inline

Checks whether the queue contains a specific element.

Parameters
valuethe value to be compared
Precondition
value_type shall be EqualityComparable.
Returns
true if found; false otherwise

◆ empty()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
bool nvwa::fc_queue< _Tp, _Alloc >::empty ( ) const
inlinenoexcept

Checks whether the queue is empty (containing no elements).

Returns
true if it is empty; false otherwise

◆ front() [1/2]

template<class _Tp, class _Alloc = std::allocator<_Tp>>
reference nvwa::fc_queue< _Tp, _Alloc >::front ( )
inline

Gets the first element in the queue.

Returns
reference to the first element

◆ front() [2/2]

template<class _Tp, class _Alloc = std::allocator<_Tp>>
const_reference nvwa::fc_queue< _Tp, _Alloc >::front ( ) const
inline

Gets the first element in the queue.

Returns
const reference to the first element

◆ full()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
bool nvwa::fc_queue< _Tp, _Alloc >::full ( ) const
inlinenoexcept

Checks whether the queue is full (containing the maximum allowed elements).

Returns
true if it is full; false otherwise

◆ get_allocator()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
allocator_type nvwa::fc_queue< _Tp, _Alloc >::get_allocator ( ) const
inline

Gets the allocator of the queue.

Returns
the allocator of the queue

◆ operator=()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
fc_queue& nvwa::fc_queue< _Tp, _Alloc >::operator= ( const fc_queue< _Tp, _Alloc > &  rhs)
inline

Assignment operator that copies all elements from another queue.

Parameters
rhsthe queue to copy
Postcondition
If assignment is successful (no exception is thrown during memory allocation and element copy), this queue will have the same elements as rhs. Otherwise this queue is unchanged (strong exception safety is guaranteed).

◆ pop()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
void nvwa::fc_queue< _Tp, _Alloc >::pop ( )
inline

Discards the first element in the queue.

Precondition
This queue is not empty.
Postcondition
One element is discarded at the front, size() is decremented by one, and full() is false.

◆ push()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
void nvwa::fc_queue< _Tp, _Alloc >::push ( const value_type &  value)
inline

Inserts a new element at the end of the queue.

The first element will be discarded if the queue is full.

Parameters
valuethe value to be inserted
Postcondition
size() <= capacity() && back() == value, unless an exception is thrown, in which case this queue is unchanged (strong exception safety is guaranteed).

◆ size()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
size_type nvwa::fc_queue< _Tp, _Alloc >::size ( ) const
inlinenoexcept

Gets the number of existing elements in the queue.

Returns
the number of existing elements in the queue

◆ swap()

template<class _Tp, class _Alloc = std::allocator<_Tp>>
void nvwa::fc_queue< _Tp, _Alloc >::swap ( fc_queue< _Tp, _Alloc > &  rhs)
inline

Exchanges the elements of two queues.

Parameters
rhsthe queue to exchange with
Postcondition
If swapping the allocators does not throw, *this will be swapped with rhs. If swapping the allocators throws with strong exception safety guarantee, this function will also provide such guarantee.

The documentation for this class was generated from the following file: