tlx
|
A ring (circular) buffer of static (non-growing) size. More...
#include <ring_buffer.hpp>
Public Types | |
using | value_type = Type |
using | allocator_type = Allocator |
using | alloc_traits = std::allocator_traits< allocator_type > |
using | reference = typename allocator_type::reference |
using | const_reference = typename allocator_type::const_reference |
using | pointer = typename allocator_type::pointer |
using | const_pointer = typename allocator_type::const_pointer |
using | size_type = typename allocator_type::size_type |
using | difference_type = typename allocator_type::difference_type |
Public Member Functions | |
RingBuffer (const Allocator &alloc=allocator_type()) noexcept | |
RingBuffer (size_t max_size, const Allocator &alloc=allocator_type()) | |
RingBuffer (const RingBuffer &rb) | |
copy-constructor: create new ring buffer More... | |
RingBuffer & | operator= (const RingBuffer &rb) |
copyable: create new ring buffer More... | |
RingBuffer (RingBuffer &&rb) noexcept | |
move-constructor: move buffer More... | |
RingBuffer & | operator= (RingBuffer &&rb) noexcept |
move-assignment operator: default More... | |
~RingBuffer () | |
void | allocate (size_t max_size) |
allocate buffer More... | |
void | deallocate () |
deallocate buffer More... | |
Modifiers | |
void | push_back (const value_type &t) |
add element at the end More... | |
void | push_back (value_type &&t) |
add element at the end More... | |
template<typename... Args> | |
void | emplace_back (Args &&... args) |
emplace element at the end More... | |
void | push_front (const value_type &t) |
add element at the beginning More... | |
void | push_front (value_type &&t) |
add element at the beginning More... | |
template<typename... Args> | |
void | emplace_front (Args &&... args) |
emplace element at the beginning More... | |
void | pop_front () |
remove element at the beginning More... | |
void | pop_back () |
remove element at the end More... | |
void | clear () |
reset buffer contents More... | |
void | copy_to (std::vector< value_type > *out) const |
copy all element into the vector More... | |
void | move_to (std::vector< value_type > *out) |
move all element from the RingBuffer into the vector More... | |
Element access | |
reference | operator[] (size_type i) noexcept |
Returns a reference to the i-th element. More... | |
const_reference | operator[] (size_type i) const noexcept |
Returns a reference to the i-th element. More... | |
reference | front () noexcept |
Returns a reference to the first element. More... | |
const_reference | front () const noexcept |
Returns a reference to the first element. More... | |
reference | back () noexcept |
Returns a reference to the last element. More... | |
const_reference | back () const noexcept |
Returns a reference to the last element. More... | |
Capacity | |
size_type | size () const noexcept |
return the number of items in the buffer More... | |
size_t | max_size () const noexcept |
return the maximum number of items in the buffer. More... | |
size_t | capacity () const noexcept |
return actual capacity of the ring buffer. More... | |
bool | empty () const noexcept |
returns true if no items are in the buffer More... | |
Serialization Methods for cereal | |
template<class Archive > | |
void | save (Archive &ar) const |
template<class Archive > | |
void | load (Archive &ar) |
Protected Attributes | |
size_t | max_size_ |
target max_size of circular buffer prescribed by the user. More... | |
allocator_type | alloc_ |
used allocator More... | |
size_t | capacity_ |
capacity of data buffer. More... | |
size_t | mask_ |
one-bits mask for calculating modulo of capacity using AND-mask. More... | |
Type * | data_ |
the circular buffer of static size. More... | |
size_type | begin_ |
iterator at current begin of ring buffer More... | |
size_type | end_ |
iterator at current begin of ring buffer More... | |
A ring (circular) buffer of static (non-growing) size.
Due to many modulo operations with capacity_, the capacity is rounded up to the next power of two, even for powers of two! This is because otherwise size() == end - begin == 0 after filling the ring buffer, and adding another size_ member requires more book-keeping.
Definition at line 44 of file ring_buffer.hpp.
using alloc_traits = std::allocator_traits<allocator_type> |
Definition at line 50 of file ring_buffer.hpp.
using allocator_type = Allocator |
Definition at line 48 of file ring_buffer.hpp.
using const_pointer = typename allocator_type::const_pointer |
Definition at line 55 of file ring_buffer.hpp.
using const_reference = typename allocator_type::const_reference |
Definition at line 53 of file ring_buffer.hpp.
using difference_type = typename allocator_type::difference_type |
Definition at line 58 of file ring_buffer.hpp.
using pointer = typename allocator_type::pointer |
Definition at line 54 of file ring_buffer.hpp.
using reference = typename allocator_type::reference |
Definition at line 52 of file ring_buffer.hpp.
using size_type = typename allocator_type::size_type |
Definition at line 57 of file ring_buffer.hpp.
using value_type = Type |
Definition at line 47 of file ring_buffer.hpp.
|
inlineexplicitnoexcept |
Definition at line 65 of file ring_buffer.hpp.
|
inlineexplicit |
Definition at line 69 of file ring_buffer.hpp.
|
inline |
copy-constructor: create new ring buffer
Definition at line 77 of file ring_buffer.hpp.
|
inlinenoexcept |
move-constructor: move buffer
Definition at line 115 of file ring_buffer.hpp.
|
inline |
Definition at line 146 of file ring_buffer.hpp.
|
inline |
allocate buffer
Definition at line 152 of file ring_buffer.hpp.
|
inlinenoexcept |
Returns a reference to the last element.
Definition at line 287 of file ring_buffer.hpp.
|
inlinenoexcept |
Returns a reference to the last element.
Definition at line 282 of file ring_buffer.hpp.
|
inlinenoexcept |
return actual capacity of the ring buffer.
Definition at line 308 of file ring_buffer.hpp.
|
inline |
reset buffer contents
Definition at line 235 of file ring_buffer.hpp.
|
inline |
copy all element into the vector
Definition at line 241 of file ring_buffer.hpp.
|
inline |
deallocate buffer
Definition at line 161 of file ring_buffer.hpp.
|
inline |
emplace element at the end
Definition at line 189 of file ring_buffer.hpp.
|
inline |
emplace element at the beginning
Definition at line 213 of file ring_buffer.hpp.
|
inlinenoexcept |
returns true if no items are in the buffer
Definition at line 313 of file ring_buffer.hpp.
|
inlinenoexcept |
Returns a reference to the first element.
Definition at line 276 of file ring_buffer.hpp.
|
inlinenoexcept |
Returns a reference to the first element.
Definition at line 271 of file ring_buffer.hpp.
|
inline |
Definition at line 330 of file ring_buffer.hpp.
|
inlinenoexcept |
return the maximum number of items in the buffer.
Definition at line 303 of file ring_buffer.hpp.
|
inline |
move all element from the RingBuffer into the vector
Definition at line 247 of file ring_buffer.hpp.
|
inline |
copyable: create new ring buffer
Definition at line 91 of file ring_buffer.hpp.
|
inlinenoexcept |
move-assignment operator: default
Definition at line 128 of file ring_buffer.hpp.
|
inlinenoexcept |
Returns a reference to the i-th element.
Definition at line 265 of file ring_buffer.hpp.
Returns a reference to the i-th element.
Definition at line 260 of file ring_buffer.hpp.
|
inline |
remove element at the end
Definition at line 228 of file ring_buffer.hpp.
|
inline |
remove element at the beginning
Definition at line 221 of file ring_buffer.hpp.
|
inline |
add element at the end
Definition at line 173 of file ring_buffer.hpp.
|
inline |
add element at the end
Definition at line 180 of file ring_buffer.hpp.
|
inline |
add element at the beginning
Definition at line 197 of file ring_buffer.hpp.
|
inline |
add element at the beginning
Definition at line 204 of file ring_buffer.hpp.
|
inline |
Definition at line 323 of file ring_buffer.hpp.
|
inlinenoexcept |
return the number of items in the buffer
Definition at line 298 of file ring_buffer.hpp.
|
protected |
used allocator
Definition at line 362 of file ring_buffer.hpp.
|
protected |
iterator at current begin of ring buffer
Definition at line 375 of file ring_buffer.hpp.
|
protected |
capacity of data buffer.
rounded up from max_size_ to next unequal power of two.
Definition at line 366 of file ring_buffer.hpp.
|
protected |
the circular buffer of static size.
Definition at line 372 of file ring_buffer.hpp.
|
protected |
iterator at current begin of ring buffer
Definition at line 378 of file ring_buffer.hpp.
|
protected |
one-bits mask for calculating modulo of capacity using AND-mask.
Definition at line 369 of file ring_buffer.hpp.
|
protected |
target max_size of circular buffer prescribed by the user.
Never equal to the data_.size(), which is rounded up to a power of two.
Definition at line 359 of file ring_buffer.hpp.