libboxes
boxes is a set of specialised containers built on top of STL
|
Implements a fixed-size double ended queue. More...
#include <ring_buffer.hpp>
Public Member Functions | |
RingBuffer (const RingBuffer< T, SizeV > &other) | |
Copy constructs a RingBuffer from another. More... | |
RingBuffer (RingBuffer< T, SizeV > &&other) | |
Move constructs a RingBuffer from another. More... | |
RingBuffer< T, SizeV > & | operator= (const RingBuffer< T, SizeV > &other) |
Copy the contents of another RingBuffer into this one. More... | |
RingBuffer< T, SizeV > & | operator= (RingBuffer< T, SizeV > &&other) |
Moves the contents of another RingBuffer into this one. More... | |
iterator | begin () |
Returns an iterator to the first element in the RingBuffer. More... | |
iterator | end () |
Returns an iterator to the end of the RingBuffer. More... | |
iterator | cbegin () const |
Returns a const iterator to the first element in the RingBuffer. More... | |
iterator | cend () const |
Returns a const iterator to the end of the RingBuffer. More... | |
bool | empty () const BOXES_NOTHROW |
Returns true if the RingBuffer is empty. More... | |
bool | full () const BOXES_NOTHROW |
Returns true if the RingBuffer is full. More... | |
T & | back () |
Returns the last element in the queue. More... | |
T & | front () |
Returns the first element in the queue. More... | |
const T & | front () const |
Version of front that can be used with const RingBuffers. More... | |
const T & | back () const |
Version of back that can be used with const RingBuffers. More... | |
T & | operator[] (size_type pos) |
Allows for random access to the elements in the RingBuffer. More... | |
const T & | operator[] (size_type pos) const |
Returns a const reference to the element at position pos More... | |
T & | at (size_type pos) |
Allows for random access to the elements in the RingBuffer. More... | |
const T & | at (size_type pos) const |
Const version of at More... | |
bool | operator== (const RingBuffer< T, SizeV > &other) const |
Returns true if the contents of this RingBuffer are equal to another. More... | |
bool | operator!= (const RingBuffer< T, SizeV > &other) const |
Returns true if the contents of this RingBuffer are not equal to another. More... | |
void | swap (RingBuffer< T, SizeV > &other) |
Swaps the contents of this RingBuffer with another. More... | |
template<typename Arg > | |
bool | push_back (Arg &&value) |
Inserts a new element at the end of the RingBuffer. More... | |
template<typename Arg > | |
bool | push_front (Arg &&value) |
Inserts a new element at the front of the RingBuffer. More... | |
bool | pop_back () |
Removes the last element from the RingBuffer. More... | |
bool | pop_front () |
Removes the first element from the RingBuffer. More... | |
size_type | size () const BOXES_NOTHROW |
Returns the number of elements in the RingBuffer. More... | |
void | clear () |
Clears the contents of the RingBuffer. More... | |
Implements a fixed-size double ended queue.
Elements can be added to the front of the buffer in O(1) time, and removed from the back in O(1) time as well. Additionally, the buffer implements iterators to allow traversal of the contents.
T | The type of the elements to be stored in the buffer |
SizeV | The maximum number of elements that can be stored in the buffer |
Definition at line 31 of file ring_buffer.hpp.
|
inline |
Copy constructs a RingBuffer from another.
other |
Definition at line 99 of file ring_buffer.hpp.
|
inline |
Move constructs a RingBuffer from another.
other |
Definition at line 107 of file ring_buffer.hpp.
|
inline |
Allows for random access to the elements in the RingBuffer.
The semantics of this method are the same as the operator[]
method, but bounds checking is performed. std::out_of_range
will be thrown if pos
is greater than or equal to the size of the RingBuffer.
pos | The position of the element to be accessed |
pos
Definition at line 265 of file ring_buffer.hpp.
|
inline |
Const version of at
pos | The position of the element to be accessed |
pos
Definition at line 278 of file ring_buffer.hpp.
|
inline |
Returns the last element in the queue.
Since this RingBuffer is a FIFO, the back
element is the one that was most recently inserted into the RingBuffer.
Definition at line 194 of file ring_buffer.hpp.
|
inline |
Version of back
that can be used with const RingBuffers.
Definition at line 228 of file ring_buffer.hpp.
|
inline |
Returns an iterator to the first element in the RingBuffer.
The first element in the RingBuffer is the one that was inserted first, is retrievable with the front
method.
Definition at line 149 of file ring_buffer.hpp.
|
inline |
Returns a const iterator to the first element in the RingBuffer.
Definition at line 163 of file ring_buffer.hpp.
|
inline |
Returns a const iterator to the end of the RingBuffer.
Definition at line 170 of file ring_buffer.hpp.
|
inline |
Clears the contents of the RingBuffer.
This method will remove all elements from the RingBuffer, leaving it in an empty state.
Definition at line 424 of file ring_buffer.hpp.
|
inline |
Returns true if the RingBuffer is empty.
Definition at line 177 of file ring_buffer.hpp.
|
inline |
Returns an iterator to the end of the RingBuffer.
Definition at line 156 of file ring_buffer.hpp.
|
inline |
Returns the first element in the queue.
Since this RingBuffer is a FIFO, the front
element is the one that was inserted into the RingBuffer first.
Definition at line 209 of file ring_buffer.hpp.
|
inline |
Version of front
that can be used with const RingBuffers.
Definition at line 221 of file ring_buffer.hpp.
|
inline |
Returns true if the RingBuffer is full.
Definition at line 184 of file ring_buffer.hpp.
|
inline |
Returns true if the contents of this RingBuffer are not equal to another.
Performs a lexicographical comparison of the contents of this RingBuffer.
other | The RingBuffer to compare with |
Definition at line 313 of file ring_buffer.hpp.
|
inline |
Copy the contents of another RingBuffer into this one.
other |
Definition at line 119 of file ring_buffer.hpp.
|
inline |
Moves the contents of another RingBuffer into this one.
other |
Definition at line 133 of file ring_buffer.hpp.
|
inline |
Returns true if the contents of this RingBuffer are equal to another.
Performs a lexicographical comparison of the contents of this RingBuffer.
other | The RingBuffer to compare with |
Definition at line 290 of file ring_buffer.hpp.
|
inline |
Allows for random access to the elements in the RingBuffer.
The element at position pos
is the pos
th element inserted with pos
th push_back call.
No bounds checking is performed. It's safe to use this method with pos
greater than or equal to the size of the RingBuffer. If pos
is greater than or equal to the size of the RingBuffer, the pos
will wrap around.
pos | The position of the element to be accessed |
pos
Definition at line 243 of file ring_buffer.hpp.
|
inline |
Returns a const reference to the element at position pos
pos | The position of the element to be accessed |
pos
Definition at line 251 of file ring_buffer.hpp.
|
inline |
Removes the last element from the RingBuffer.
The element to be removed is the element that was most recently inserted with push_back
.
Definition at line 379 of file ring_buffer.hpp.
|
inline |
Removes the first element from the RingBuffer.
The element to be removed is the element retrieable with the front
method.
Definition at line 397 of file ring_buffer.hpp.
|
inline |
Inserts a new element at the end of the RingBuffer.
Newly inserted elements will be placed at the end of the RingBuffer. Newly inserted element can be accessed using the back
method.
Arg | The type of the element to be inserted |
value | The value of the element to be inserted |
Definition at line 340 of file ring_buffer.hpp.
|
inline |
Inserts a new element at the front of the RingBuffer.
Newly inserted elements will be placed at the front of the RingBuffer. Newly inserted element can be accessed using the front
method.
Arg | The type of the element to be inserted |
value | The value of the element to be inserted |
Definition at line 360 of file ring_buffer.hpp.
|
inline |
Returns the number of elements in the RingBuffer.
Definition at line 411 of file ring_buffer.hpp.
|
inline |
Swaps the contents of this RingBuffer with another.
Required to implement the Container requirements of the C++ standard.
other | The RingBuffer to swap with |
Definition at line 324 of file ring_buffer.hpp.