23 #ifndef EDSP_FIXED_RING_BUFFER_HPP 24 #define EDSP_FIXED_RING_BUFFER_HPP 26 #include <edsp/meta/unused.hpp> 30 namespace edsp {
inline namespace types {
45 template <
typename T, std::
size_t MaxSize>
49 typedef typename ring_span<T>::pointer
pointer;
51 typedef typename ring_span<value_type>::reference
reference;
53 typedef typename ring_span<value_type>::iterator
iterator;
57 typedef typename ring_span<value_type>::size_type
size_type;
83 ring_ = edsp::ring_span<T>(std::begin(buffer_), std::end(buffer_));
104 const_iterator
begin() const noexcept {
105 return ring_.begin();
126 const_iterator
end() const noexcept {
137 return ring_.rbegin();
147 const_reverse_iterator
rbegin() const noexcept {
148 return ring_.rbegin();
158 reverse_iterator
rend() noexcept {
169 const_reverse_iterator
rend() const noexcept {
181 return ring_.cbegin();
191 const_iterator
cend() const noexcept {
202 const_reverse_iterator
crbegin() const noexcept {
203 return ring_.crbegin();
213 const_reverse_iterator
crend() const noexcept {
214 return ring_.crend();
238 return ring_.empty();
254 return ring_.capacity();
298 reference
at(std::size_t i) {
313 const_reference
at(std::size_t i)
const {
323 return ring_.front();
332 return ring_.front();
361 template <
typename... Args>
363 ring_.emplace_front(arg...);
374 template <
typename... Args>
376 ring_.emplace_back(arg...);
388 ring_.push_back(item);
430 return buffer_.data();
434 container_type buffer_{};
435 edsp::ring_span<T> ring_{std::begin(buffer_), std::end(buffer_)};
440 #endif //EDSP_FIXED_RING_BUFFER_HPP This class implements a ring buffer, also called circular buffer.
Definition: fixed_ring_buffer.hpp:46
const_iterator cbegin() const noexcept
Returns a read-only iterator that points to the first element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:180
ring_span< value_type >::const_reference const_reference
Definition: fixed_ring_buffer.hpp:52
const_reverse_iterator rbegin() const noexcept
Returns a read-only iterator that points to the first element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:147
const_reference at(std::size_t i) const
Provides access to the data contained in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:313
size_type size() const
Returns the number of elements in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:221
bool full() const
Definition: fixed_ring_buffer.hpp:245
const_reverse_iterator crbegin() const noexcept
Returns a read-only iterator that points to the first element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:202
reverse_iterator rbegin() noexcept
Definition: fixed_ring_buffer.hpp:136
ring_span< value_type >::reverse_iterator reverse_iterator
Definition: fixed_ring_buffer.hpp:55
void clear()
Definition: fixed_ring_buffer.hpp:82
bool empty() const
Definition: fixed_ring_buffer.hpp:237
const_iterator cend() const noexcept
Returns a read-only te iterator that points to the last element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:191
size_type capacity() const
Definition: fixed_ring_buffer.hpp:253
const_iterator begin() const noexcept
Returns a read-only iterator that points to the first element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:104
reference front()
Returns a read/write reference to the data at the first element of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:322
size_type max_size() const
Definition: fixed_ring_buffer.hpp:229
iterator begin() noexcept
Returns a read/write iterator that points to the first element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:93
const_reference operator[](std::size_t i) const
Subscript access to the data contained in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:283
void emplace_back(Args... arg)
Inserts an object at the end of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:375
void pop_front()
Removes the first element of the ring.
Definition: fixed_ring_buffer.hpp:400
const container_type & buffer() const
Returns a const reference to the internal buffer.
Definition: fixed_ring_buffer.hpp:421
reverse_iterator rend() noexcept
Returns a read/write iterator that points to the last element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:158
iterator end() noexcept
Returns a read/write iterator that points to the last element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:115
reference operator[](std::size_t i)
Subscript access to the data contained in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:268
void emplace_front(Args... arg)
Inserts an object at the front of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:362
fixed_ring_buffer()=default
const_reverse_iterator rend() const noexcept
Definition: fixed_ring_buffer.hpp:169
reference at(std::size_t i)
Provides access to the data contained in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:298
std::ptrdiff_t difference_type
Definition: fixed_ring_buffer.hpp:58
ring_span< value_type >::size_type size_type
Definition: fixed_ring_buffer.hpp:57
ring_span< T >::pointer pointer
Definition: fixed_ring_buffer.hpp:49
void push_back(const value_type &item)
Add data to the end of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:387
const_pointer * data() const
Returns a const pointer to the underlying data of the internal buffer.
Definition: fixed_ring_buffer.hpp:429
ring_span< value_type >::const_reverse_iterator const_reverse_iterator
Definition: fixed_ring_buffer.hpp:56
const_reference back() const
Returns a read-only reference to the data at the last element of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:349
void pop_back()
Removes the last element of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:413
const_reverse_iterator crend() const noexcept
Returns a read-only iterator that points to the last element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:213
ring_span< value_type >::iterator iterator
Definition: fixed_ring_buffer.hpp:53
ring_span< T >::value_type value_type
Definition: fixed_ring_buffer.hpp:48
reference back()
Returns a read/write reference to the data at the last element of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:340
const_reference front() const
Returns a read-only reference to the data at the first element of the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:331
ring_span< value_type >::reference reference
Definition: fixed_ring_buffer.hpp:51
ring_span< value_type >::const_iterator const_iterator
Definition: fixed_ring_buffer.hpp:54
std::array< T, MaxSize > container_type
Definition: fixed_ring_buffer.hpp:59
Definition: amplifier.hpp:29
const_iterator end() const noexcept
Returns a read-only iterator that points to the last element in the fixed_ring_buffer.
Definition: fixed_ring_buffer.hpp:126
std::add_const_t< pointer > const_pointer
Definition: fixed_ring_buffer.hpp:50