7 #include "common/util.h" 16 template<
typename TYPE,
size_t SIZE = 64u>
25 using value_type = TYPE;
27 RingBuffer() : _size(0u), _front(0u), _back(SIZE - 1u) {
39 inline const TYPE &operator*()
const {
40 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
43 inline TYPE &operator*() {
44 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
47 inline const TYPE &operator()()
const {
48 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
51 inline TYPE &operator()() {
52 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
60 inline bool operator!=(
const iterator &rhs)
const {
61 return _ringBuffer != rhs._ringBuffer || _idx != rhs._idx;
64 inline bool operator==(
const iterator &rhs)
const {
65 return _ringBuffer == rhs._ringBuffer && _idx == rhs._idx;
68 inline const TYPE *operator->()
const {
69 return &_ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
78 return iterator(
this, _front + _size);
82 return iterator(const_cast<RingBuffer *>(
this), _front);
86 return iterator(const_cast<RingBuffer *>(
this), _front + _size);
89 inline size_t size()
const {
93 constexpr
size_t capacity()
const {
97 inline bool empty()
const {
106 return _buffer[_front];
114 return _buffer[_front];
122 return _buffer[_back];
130 return _buffer[_back];
147 _back = (_back + 1u) % SIZE;
149 _front = (_front + 1u) % SIZE;
160 template<
typename... _Args>
162 _back = (_back + 1u) % SIZE;
164 _front = (_front + 1u) % SIZE;
168 _buffer[_back] =
Common::move(TYPE{Common::forward<_Args>(args)...});
179 _front = (_front + 1u) % SIZE;
191 _back = (_front + _size - 1u) % SIZE;
202 _front = (_front + n) % SIZE;
206 inline TYPE &operator[](
size_t i) {
207 return _buffer[(_front + i) % SIZE];
210 inline const TYPE &operator[](
size_t i)
const {
211 return _buffer[(_front + i) % SIZE];
void pop()
Removes element from the beginning of the buffer.
Definition: ringbuffer.h:174
void emplace_back(_Args &&...args)
Pushes an elements to the end of the buffer.
Definition: ringbuffer.h:161
Non allocating buffer class holds a maximum of given entries and allows an endless insert by overrind...
Definition: ringbuffer.h:17
Definition: ringbuffer.h:30
void erase_back(const size_t n)
Erase the given amount of elements from the end of the buffer.
Definition: ringbuffer.h:185
void clear()
Clears the whole ring buffer.
Definition: ringbuffer.h:137
TYPE & front()
Access to the first element in the buffer.
Definition: ringbuffer.h:113
void push_back(const TYPE &x)
Pushes an element to the end of the buffer.
Definition: ringbuffer.h:146
void erase_front(const size_t n)
Erase the given amount of elements from the beginning of the buffer.
Definition: ringbuffer.h:197
const TYPE & back() const
Access to the last element in the buffer.
Definition: ringbuffer.h:121
Definition: achievements_tables.h:27
const TYPE & front() const
Access to the first element in the buffer.
Definition: ringbuffer.h:105
Out move(In first, In last, Out dst)
Definition: algorithm.h:109
TYPE & back()
Access to the last element in the buffer.
Definition: ringbuffer.h:129