26 #ifndef EDSP_RING_BUFFER_HPP 27 #define EDSP_RING_BUFFER_HPP 29 #include <edsp/meta/unused.hpp> 33 namespace edsp {
inline namespace types {
48 template <
typename T,
typename Allocator = std::allocator<T>>
52 typedef typename ring_span<T>::pointer
pointer;
54 typedef typename ring_span<value_type>::reference
reference;
56 typedef typename ring_span<value_type>::iterator
iterator;
60 typedef typename ring_span<value_type>::size_type
size_type;
79 ring_ = edsp::ring_span<T>(std::begin(buffer_), std::end(buffer_));
90 ring_ = edsp::ring_span<T>(std::begin(buffer_), std::end(buffer_), std::begin(buffer_), N);
109 buffer_.resize(size);
110 ring_ = edsp::ring_span<T>(std::begin(buffer_), std::end(buffer_));
120 ring_ = edsp::ring_span<T>(std::begin(buffer_), std::end(buffer_), std::begin(buffer_), 0);
131 return ring_.begin();
141 const_iterator
begin() const noexcept {
142 return ring_.begin();
163 const_iterator
end() const noexcept {
174 return ring_.rbegin();
184 const_reverse_iterator
rbegin() const noexcept {
185 return ring_.rbegin();
195 reverse_iterator
rend() noexcept {
206 const_reverse_iterator
rend() const noexcept {
218 return ring_.cbegin();
228 const_iterator
cend() const noexcept {
239 const_reverse_iterator
crbegin() const noexcept {
240 return ring_.crbegin();
250 const_reverse_iterator
crend() const noexcept {
251 return ring_.crend();
258 constexpr size_type
size()
const {
267 return buffer_.max_size();
275 return ring_.empty();
291 return ring_.capacity();
335 reference
at(std::size_t i) {
350 const_reference
at(std::size_t i)
const {
360 return ring_.front();
369 return ring_.front();
398 template <
typename... Args>
400 ring_.emplace_front(arg...);
411 template <
typename... Args>
413 ring_.emplace_back(arg...);
425 ring_.push_back(item);
467 return buffer_.data();
471 container_type buffer_{};
472 edsp::ring_span<T> ring_{std::begin(buffer_), std::end(buffer_)};
477 #endif //EDSP_RING_BUFFER_HPP ring_span< value_type >::size_type size_type
Definition: ring_buffer.hpp:60
std::add_const_t< pointer > const_pointer
Definition: ring_buffer.hpp:53
ring_span< value_type >::const_iterator const_iterator
Definition: ring_buffer.hpp:57
void pop_front()
Removes the first element of the ring.
Definition: ring_buffer.hpp:437
reference at(std::size_t i)
Provides access to the data contained in the ring_buffer.
Definition: ring_buffer.hpp:335
const_reverse_iterator crbegin() const noexcept
Returns a read-only iterator that points to the first element in the ring_buffer. ...
Definition: ring_buffer.hpp:239
iterator begin() noexcept
Returns a read/write iterator that points to the first element in the ring_buffer.
Definition: ring_buffer.hpp:130
void resize(size_type size)
Resizes the ring_buffer to the specified number of elements.
Definition: ring_buffer.hpp:108
void emplace_back(Args... arg)
Inserts an object at the end of the ring_buffer.
Definition: ring_buffer.hpp:412
std::ptrdiff_t difference_type
Definition: ring_buffer.hpp:61
ring_span< value_type >::reference reference
Definition: ring_buffer.hpp:54
ring_span< value_type >::reverse_iterator reverse_iterator
Definition: ring_buffer.hpp:58
const_reverse_iterator rbegin() const noexcept
Returns a read-only iterator that points to the first element in the ring_buffer. ...
Definition: ring_buffer.hpp:184
const_reference at(std::size_t i) const
Provides access to the data contained in the ring_buffer.
Definition: ring_buffer.hpp:350
This class implements a ring buffer, also called circular buffer.
Definition: ring_buffer.hpp:49
const_iterator begin() const noexcept
Returns a read-only iterator that points to the first element in the ring_buffer. ...
Definition: ring_buffer.hpp:141
const container_type & buffer() const
Returns a const reference to the internal buffer.
Definition: ring_buffer.hpp:458
ring_span< value_type >::iterator iterator
Definition: ring_buffer.hpp:56
const_reverse_iterator crend() const noexcept
Returns a read-only iterator that points to the last element in the ring_buffer.
Definition: ring_buffer.hpp:250
ring_span< T >::value_type value_type
Definition: ring_buffer.hpp:51
reference front()
Returns a read/write reference to the data at the first element of the ring_buffer.
Definition: ring_buffer.hpp:359
reverse_iterator rbegin() noexcept
Definition: ring_buffer.hpp:173
~ring_buffer()=default
Default destructor. The dtor only erases the elements, and note that if the elements themselves are p...
constexpr size_type max_size() const
Definition: ring_buffer.hpp:266
constexpr size_type size() const
Returns the number of elements in the ring_buffer.
Definition: ring_buffer.hpp:258
const_reference back() const
Returns a read-only reference to the data at the last element of the ring_buffer. ...
Definition: ring_buffer.hpp:386
void clear()
Definition: ring_buffer.hpp:119
iterator end() noexcept
Returns a read/write iterator that points to the last element in the ring_buffer. ...
Definition: ring_buffer.hpp:152
const_iterator cend() const noexcept
Returns a read-only te iterator that points to the last element in the ring_buffer.
Definition: ring_buffer.hpp:228
const_reference operator[](std::size_t i) const
Subscript access to the data contained in the ring_buffer.
Definition: ring_buffer.hpp:320
reference operator[](std::size_t i)
Subscript access to the data contained in the ring_buffer.
Definition: ring_buffer.hpp:305
reference back()
Returns a read/write reference to the data at the last element of the ring_buffer.
Definition: ring_buffer.hpp:377
ring_span< value_type >::const_reverse_iterator const_reverse_iterator
Definition: ring_buffer.hpp:59
const_iterator cbegin() const noexcept
Returns a read-only iterator that points to the first element in the ring_buffer. ...
Definition: ring_buffer.hpp:217
ring_span< value_type >::const_reference const_reference
Definition: ring_buffer.hpp:55
constexpr bool empty() const
Definition: ring_buffer.hpp:274
void pop_back()
Removes the last element of the ring_buffer.
Definition: ring_buffer.hpp:450
reverse_iterator rend() noexcept
Returns a read/write iterator that points to the last element in the ring_buffer. ...
Definition: ring_buffer.hpp:195
const_reference front() const
Returns a read-only reference to the data at the first element of the ring_buffer.
Definition: ring_buffer.hpp:368
ring_buffer(size_type N, const value_type &value)
Creates a ring_buffer with copies of an exemplar element.
Definition: ring_buffer.hpp:88
void push_back(const value_type &item)
Add data to the end of the ring_buffer.
Definition: ring_buffer.hpp:424
ring_span< T >::pointer pointer
Definition: ring_buffer.hpp:52
const_pointer * data() const
Returns a const pointer to the underlying data of the internal buffer.
Definition: ring_buffer.hpp:466
void emplace_front(Args... arg)
Inserts an object at the front of the ring_buffer.
Definition: ring_buffer.hpp:399
const_reverse_iterator rend() const noexcept
Definition: ring_buffer.hpp:206
const_iterator end() const noexcept
Returns a read-only iterator that points to the last element in the ring_buffer.
Definition: ring_buffer.hpp:163
constexpr ring_buffer()=default
Definition: amplifier.hpp:29
constexpr bool full() const
Definition: ring_buffer.hpp:282
std::vector< T, Allocator > container_type
Definition: ring_buffer.hpp:62
constexpr size_type capacity() const
Definition: ring_buffer.hpp:290