nvwa::fc_queue< _Tp, _Alloc > Class Template Reference

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

#include <fc_queue.h>

Collaboration diagram for nvwa::fc_queue< _Tp, _Alloc >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef _Tp value_type
typedef _Alloc allocator_type
typedef size_t size_type
typedef value_typepointer
typedef const value_typeconst_pointer
typedef value_typereference
typedef const value_typeconst_reference

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

Protected Member Functions

pointer increment (pointer ptr) const noexcept
pointer decrement (pointer ptr) const noexcept
void construct (void *ptr, const _Tp &value)
void destroy (void *ptr)

Protected Attributes

pointer _M_head
pointer _M_tail
pointer _M_begin
pointer _M_end
allocator_type _M_alloc

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:
_Tp the type of elements in the queue
_Alloc allocator 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).

Member Typedef Documentation

template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef _Alloc nvwa::fc_queue< _Tp, _Alloc >::allocator_type
template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef const value_type* nvwa::fc_queue< _Tp, _Alloc >::const_pointer
template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef const value_type& nvwa::fc_queue< _Tp, _Alloc >::const_reference
template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef value_type* nvwa::fc_queue< _Tp, _Alloc >::pointer
template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef value_type& nvwa::fc_queue< _Tp, _Alloc >::reference
template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef size_t nvwa::fc_queue< _Tp, _Alloc >::size_type
template<class _Tp , class _Alloc = std::allocator<_Tp>>
typedef _Tp nvwa::fc_queue< _Tp, _Alloc >::value_type

Constructor & Destructor Documentation

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() 
) [inline, explicit]

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

Parameters:
max_size the maximum size allowed
alloc the 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:
template<class _Tp , class _Alloc >
nvwa::fc_queue< _Tp, _Alloc >::fc_queue ( const fc_queue< _Tp, _Alloc > &  rhs  )  [inline]

Copy-constructor that copies all elements from another queue.

Parameters:
rhs the 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.
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

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
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
template<class _Tp , class _Alloc = std::allocator<_Tp>>
size_type nvwa::fc_queue< _Tp, _Alloc >::capacity (  )  const [inline]

Gets the maximum number of allowed elements in the queue.

Returns:
the maximum number of allowed elements in the queue
template<class _Tp , class _Alloc = std::allocator<_Tp>>
void nvwa::fc_queue< _Tp, _Alloc >::construct ( void *  ptr,
const _Tp &  value 
) [inline, protected]
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:
value the value to be compared
Precondition:
value_type shall be EqualityComparable.
Returns:
true if found; false otherwise
template<class _Tp , class _Alloc = std::allocator<_Tp>>
pointer nvwa::fc_queue< _Tp, _Alloc >::decrement ( pointer  ptr  )  const [inline, protected]
template<class _Tp , class _Alloc = std::allocator<_Tp>>
void nvwa::fc_queue< _Tp, _Alloc >::destroy ( void *  ptr  )  [inline, protected]
template<class _Tp , class _Alloc = std::allocator<_Tp>>
bool nvwa::fc_queue< _Tp, _Alloc >::empty (  )  const [inline]

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

Returns:
true if it is empty; false otherwise
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
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
template<class _Tp , class _Alloc = std::allocator<_Tp>>
bool nvwa::fc_queue< _Tp, _Alloc >::full (  )  const [inline]

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

Returns:
true if it is full; false otherwise
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
template<class _Tp , class _Alloc = std::allocator<_Tp>>
pointer nvwa::fc_queue< _Tp, _Alloc >::increment ( pointer  ptr  )  const [inline, protected]
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:
rhs the 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).
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.
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:
value the 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).
template<class _Tp , class _Alloc = std::allocator<_Tp>>
size_type nvwa::fc_queue< _Tp, _Alloc >::size (  )  const [inline]

Gets the number of existing elements in the queue.

Returns:
the number of existing elements in the queue
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:
rhs the 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.

Member Data Documentation

template<class _Tp , class _Alloc = std::allocator<_Tp>>
allocator_type nvwa::fc_queue< _Tp, _Alloc >::_M_alloc [protected]
template<class _Tp , class _Alloc = std::allocator<_Tp>>
pointer nvwa::fc_queue< _Tp, _Alloc >::_M_begin [protected]
template<class _Tp , class _Alloc = std::allocator<_Tp>>
pointer nvwa::fc_queue< _Tp, _Alloc >::_M_end [protected]
template<class _Tp , class _Alloc = std::allocator<_Tp>>
pointer nvwa::fc_queue< _Tp, _Alloc >::_M_head [protected]
template<class _Tp , class _Alloc = std::allocator<_Tp>>
pointer nvwa::fc_queue< _Tp, _Alloc >::_M_tail [protected]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines

Generated by  doxygen 1.6.2