7 #include "common/util.h" 15 template<
typename TYPE,
size_t SIZE = 64u>
24 using value_type = TYPE;
26 RingBuffer() : _size(0u), _front(0u), _back(SIZE - 1u) {
38 inline const TYPE &operator*()
const {
39 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
42 inline TYPE &operator*() {
43 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
46 inline const TYPE &operator()()
const {
47 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
50 inline TYPE &operator()() {
51 return _ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
59 inline bool operator!=(
const iterator &rhs)
const {
60 return _ringBuffer != rhs._ringBuffer || _idx != rhs._idx;
63 inline bool operator==(
const iterator &rhs)
const {
64 return _ringBuffer == rhs._ringBuffer && _idx == rhs._idx;
67 inline const TYPE *operator->()
const {
68 return &_ringBuffer->_buffer[_idx % _ringBuffer->capacity()];
77 return iterator(
this, _front + _size);
81 return iterator(const_cast<RingBuffer *>(
this), _front);
85 return iterator(const_cast<RingBuffer *>(
this), _front + _size);
88 inline size_t size()
const {
92 constexpr
size_t capacity()
const {
96 inline bool empty()
const {
105 return _buffer[_front];
113 return _buffer[_front];
121 return _buffer[_back];
129 return _buffer[_back];
146 _back = (_back + 1u) % SIZE;
148 _front = (_front + 1u) % SIZE;
159 template<
typename... _Args>
161 _back = (_back + 1u) % SIZE;
163 _front = (_front + 1u) % SIZE;
167 _buffer[_back] =
Common::move(TYPE{Common::forward<_Args>(args)...});
178 _front = (_front + 1u) % SIZE;
190 _back = (_front + _size - 1u) % SIZE;
201 _front = (_front + n) % SIZE;
205 inline TYPE &operator[](
size_t i) {
206 return _buffer[(_front + i) % SIZE];
209 inline const TYPE &operator[](
size_t i)
const {
210 return _buffer[(_front + i) % SIZE];
void pop()
Removes element from the beginning of the buffer.
Definition: ringbuffer.h:173
void emplace_back(_Args &&...args)
Pushes an elements to the end of the buffer.
Definition: ringbuffer.h:160
Non allocating buffer class holds a maximum of given entries and allows an endless insert by overrind...
Definition: ringbuffer.h:16
Definition: ringbuffer.h:29
void erase_back(const size_t n)
Erase the given amount of elements from the end of the buffer.
Definition: ringbuffer.h:184
void clear()
Clears the whole ring buffer.
Definition: ringbuffer.h:136
TYPE & front()
Access to the first element in the buffer.
Definition: ringbuffer.h:112
void push_back(const TYPE &x)
Pushes an element to the end of the buffer.
Definition: ringbuffer.h:145
void erase_front(const size_t n)
Erase the given amount of elements from the beginning of the buffer.
Definition: ringbuffer.h:196
const TYPE & back() const
Access to the last element in the buffer.
Definition: ringbuffer.h:120
Definition: achievements_tables.h:27
const TYPE & front() const
Access to the first element in the buffer.
Definition: ringbuffer.h:104
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:128