10#ifndef SEMF_UTILS_CORE_BUFFER_RINGBUFFER_H_
11#define SEMF_UTILS_CORE_BUFFER_RINGBUFFER_H_
82 size_t count()
const override;
91 size_t m_dataCounter = 0;
93 size_t m_writePos = 0;
108 m_writePos = (m_writePos + 1) % this->size();
109 this->data()[m_writePos] = data;
116#if defined(DEBUG) || defined(USE_SEMF_DEBUG)
126 m_readPos = (m_readPos + 1) % this->size();
127 T& data = this->data()[m_readPos];
136#if defined(DEBUG) || defined(USE_SEMF_DEBUG)
137 if (isEmpty() || pos > m_dataCounter)
145 size_t readPos = (m_readPos + pos) % this->size();
146 T& data = this->data()[readPos];
156 if (m_dataCounter == this->size())
169 if (m_dataCounter == 0)
183 size_t counter = m_dataCounter;
Buffer is a base class for buffer implementations.
T * data() const
Returns the pointer to the first element of the data array.
The RingBuffer class implements a classic circular buffer.
void reset()
Clears the buffer.
virtual T & operator[](size_t pos) const
Returns the entry from a specific position in the buffer.
virtual void put(T data)
Writes data in the buffer.
bool isFull() const
Returns if the buffer is full.
bool isEmpty() const
Returns if the buffer is empty.
size_t count() const override
Returns the number of entries stored in the buffer and not read yet.
T & get()
Returns the oldest value not read yet.