Thrill
0.1
|
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 36 of file ring_buffer.hpp.
#include <ring_buffer.hpp>
Public Types | |
using | alloc_traits = std::allocator_traits< allocator_type > |
using | allocator_type = Allocator |
using | const_pointer = typename allocator_type::const_pointer |
using | const_reference = typename allocator_type::const_reference |
using | difference_type = typename allocator_type::difference_type |
using | pointer = typename allocator_type::pointer |
using | reference = typename allocator_type::reference |
using | size_type = typename allocator_type::size_type |
using | value_type = 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 (RingBuffer &&rb) noexcept | |
move-constructor: move buffer More... | |
~RingBuffer () | |
void | allocate (size_t max_size) |
allocate buffer More... | |
void | deallocate () |
deallocate buffer More... | |
RingBuffer & | operator= (const RingBuffer &rb) |
copyable: create new ring buffer More... | |
RingBuffer & | operator= (RingBuffer &&rb) noexcept |
move-assignment operator: default 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 | |
allocator_type | alloc_ |
used allocator More... | |
size_type | begin_ = 0 |
iterator at current begin of ring buffer More... | |
size_t | capacity_ |
Type * | data_ |
the circular buffer of static size. More... | |
size_type | end_ = 0 |
iterator at current begin of ring buffer More... | |
size_t | mask_ |
one-bits mask for calculating modulo of capacity using AND-mask. More... | |
size_t | max_size_ |
using alloc_traits = std::allocator_traits<allocator_type> |
Definition at line 42 of file ring_buffer.hpp.
using allocator_type = Allocator |
Definition at line 40 of file ring_buffer.hpp.
using const_pointer = typename allocator_type::const_pointer |
Definition at line 47 of file ring_buffer.hpp.
using const_reference = typename allocator_type::const_reference |
Definition at line 45 of file ring_buffer.hpp.
using difference_type = typename allocator_type::difference_type |
Definition at line 50 of file ring_buffer.hpp.
using pointer = typename allocator_type::pointer |
Definition at line 46 of file ring_buffer.hpp.
using reference = typename allocator_type::reference |
Definition at line 44 of file ring_buffer.hpp.
using size_type = typename allocator_type::size_type |
Definition at line 49 of file ring_buffer.hpp.
using value_type = Type |
Definition at line 39 of file ring_buffer.hpp.
|
inlineexplicitnoexcept |
Definition at line 57 of file ring_buffer.hpp.
|
inlineexplicit |
Definition at line 61 of file ring_buffer.hpp.
|
inline |
copy-constructor: create new ring buffer
Definition at line 69 of file ring_buffer.hpp.
|
inlinenoexcept |
move-constructor: move buffer
Definition at line 107 of file ring_buffer.hpp.
|
inline |
Definition at line 138 of file ring_buffer.hpp.
|
inline |
allocate buffer
Definition at line 144 of file ring_buffer.hpp.
Referenced by BaseWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::StartPreOp().
|
inlinenoexcept |
Returns a reference to the last element.
Definition at line 274 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::load().
|
inlinenoexcept |
Returns a reference to the last element.
Definition at line 279 of file ring_buffer.hpp.
|
inlinenoexcept |
return actual capacity of the ring buffer.
Definition at line 300 of file ring_buffer.hpp.
|
inline |
reset buffer contents
Definition at line 227 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::deallocate(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), and RingBuffer< Input >::~RingBuffer().
|
inline |
copy all element into the vector
Definition at line 233 of file ring_buffer.hpp.
Referenced by DisjointWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PushData().
|
inline |
deallocate buffer
Definition at line 153 of file ring_buffer.hpp.
Referenced by BaseWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Dispose().
|
inline |
emplace element at the end
Definition at line 181 of file ring_buffer.hpp.
Referenced by OverlapWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PushData().
|
inline |
emplace element at the beginning
Definition at line 205 of file ring_buffer.hpp.
|
inlinenoexcept |
returns true if no items are in the buffer
Definition at line 305 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::back(), RingBuffer< Input >::front(), RingBuffer< Input >::move_to(), RingBuffer< Input >::pop_back(), and RingBuffer< Input >::pop_front().
|
inlinenoexcept |
Returns a reference to the first element.
Definition at line 263 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::move_to().
|
inlinenoexcept |
Returns a reference to the first element.
Definition at line 268 of file ring_buffer.hpp.
|
inline |
Definition at line 322 of file ring_buffer.hpp.
|
inlinenoexcept |
return the maximum number of items in the buffer.
Definition at line 295 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::allocate().
|
inline |
move all element from the RingBuffer into the vector
Definition at line 239 of file ring_buffer.hpp.
Referenced by OverlapWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Execute(), and DisjointWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Execute().
|
inline |
copyable: create new ring buffer
Definition at line 83 of file ring_buffer.hpp.
|
inlinenoexcept |
move-assignment operator: default
Definition at line 120 of file ring_buffer.hpp.
Returns a reference to the i-th element.
Definition at line 252 of file ring_buffer.hpp.
|
inlinenoexcept |
Returns a reference to the i-th element.
Definition at line 257 of file ring_buffer.hpp.
|
inline |
remove element at the end
Definition at line 220 of file ring_buffer.hpp.
|
inline |
remove element at the beginning
Definition at line 213 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::clear(), RingBuffer< Input >::move_to(), BaseWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PreOp(), and OverlapWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PushData().
|
inline |
add element at the end
Definition at line 165 of file ring_buffer.hpp.
Referenced by OverlapWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Execute(), DisjointWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Execute(), RingBuffer< Input >::load(), BaseWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::OnPreOpFile(), RingBuffer< Input >::operator=(), BaseWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PreOp(), and RingBuffer< Input >::RingBuffer().
|
inline |
add element at the end
Definition at line 172 of file ring_buffer.hpp.
|
inline |
add element at the beginning
Definition at line 189 of file ring_buffer.hpp.
|
inline |
add element at the beginning
Definition at line 196 of file ring_buffer.hpp.
|
inline |
Definition at line 315 of file ring_buffer.hpp.
|
inlinenoexcept |
return the number of items in the buffer
Definition at line 290 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::copy_to(), RingBuffer< Input >::emplace_back(), RingBuffer< Input >::emplace_front(), RingBuffer< Input >::empty(), OverlapWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Execute(), DisjointWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::Execute(), RingBuffer< Input >::operator=(), RingBuffer< Input >::operator[](), BaseWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PreOp(), RingBuffer< Input >::push_back(), RingBuffer< Input >::push_front(), OverlapWindowNode< ValueType, Input, WindowFunction, PartialWindowFunction >::PushData(), RingBuffer< Input >::RingBuffer(), and RingBuffer< Input >::save().
|
protected |
used allocator
Definition at line 354 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::allocate(), RingBuffer< Input >::deallocate(), RingBuffer< Input >::emplace_back(), RingBuffer< Input >::emplace_front(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), RingBuffer< Input >::pop_back(), RingBuffer< Input >::pop_front(), RingBuffer< Input >::push_back(), RingBuffer< Input >::push_front(), and RingBuffer< Input >::~RingBuffer().
|
protected |
iterator at current begin of ring buffer
Definition at line 367 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::clear(), RingBuffer< Input >::emplace_front(), RingBuffer< Input >::front(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), RingBuffer< Input >::operator[](), RingBuffer< Input >::pop_back(), RingBuffer< Input >::pop_front(), RingBuffer< Input >::push_front(), and RingBuffer< Input >::size().
|
protected |
capacity of data buffer. rounded up from max_size_ to next unequal power of two.
Definition at line 358 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::allocate(), RingBuffer< Input >::capacity(), RingBuffer< Input >::deallocate(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), and RingBuffer< Input >::~RingBuffer().
|
protected |
the circular buffer of static size.
Definition at line 364 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::allocate(), RingBuffer< Input >::back(), RingBuffer< Input >::deallocate(), RingBuffer< Input >::emplace_back(), RingBuffer< Input >::emplace_front(), RingBuffer< Input >::front(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), RingBuffer< Input >::operator[](), RingBuffer< Input >::pop_back(), RingBuffer< Input >::pop_front(), RingBuffer< Input >::push_back(), RingBuffer< Input >::push_front(), and RingBuffer< Input >::~RingBuffer().
|
protected |
iterator at current begin of ring buffer
Definition at line 370 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::back(), RingBuffer< Input >::clear(), RingBuffer< Input >::emplace_back(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), RingBuffer< Input >::pop_back(), RingBuffer< Input >::push_back(), and RingBuffer< Input >::size().
|
protected |
one-bits mask for calculating modulo of capacity using AND-mask.
Definition at line 361 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::allocate(), RingBuffer< Input >::back(), RingBuffer< Input >::emplace_back(), RingBuffer< Input >::emplace_front(), RingBuffer< Input >::load(), RingBuffer< Input >::operator=(), RingBuffer< Input >::operator[](), RingBuffer< Input >::pop_back(), RingBuffer< Input >::pop_front(), RingBuffer< Input >::push_back(), RingBuffer< Input >::push_front(), and RingBuffer< Input >::size().
|
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 351 of file ring_buffer.hpp.
Referenced by RingBuffer< Input >::allocate(), RingBuffer< Input >::emplace_back(), RingBuffer< Input >::emplace_front(), RingBuffer< Input >::load(), RingBuffer< Input >::max_size(), RingBuffer< Input >::operator=(), RingBuffer< Input >::push_back(), RingBuffer< Input >::push_front(), and RingBuffer< Input >::save().