nvwa::fc_queue< _Tp, _Alloc > Class Template Reference
Class to represent a fixed-capacity queue.
More...
#include <fc_queue.h>
List of all members.
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>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
Constructor & Destructor Documentation
template<class _Tp , class _Alloc = std::allocator<_Tp>>
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 >
Copy-constructor that copies all elements from another queue.
- Parameters:
-
- 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>>
Destructor.
It erases all elements and frees memory.
Member Function Documentation
template<class _Tp , class _Alloc = std::allocator<_Tp>>
Gets the last element in the queue.
- Returns:
- const reference to the last element
template<class _Tp , class _Alloc = std::allocator<_Tp>>
Gets the last element in the queue.
- Returns:
- reference to the last element
template<class _Tp , class _Alloc = std::allocator<_Tp>>
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>>
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>>
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>>
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>>
Gets the first element in the queue.
- Returns:
- const reference to the first element
template<class _Tp , class _Alloc = std::allocator<_Tp>>
Gets the first element in the queue.
- Returns:
- reference to the first element
template<class _Tp , class _Alloc = std::allocator<_Tp>>
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>>
Gets the allocator of the queue.
- Returns:
- the allocator of the queue
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
Assignment operator that copies all elements from another queue.
- Parameters:
-
- 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>>
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>>
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>>
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>>
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>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
template<class _Tp , class _Alloc = std::allocator<_Tp>>
The documentation for this class was generated from the following file: