Bluenet
5.7.0
Bluenet, firmware for nRF52 smart home devices
|
Circular Buffer implementation. More...
#include <cs_CircularBuffer.h>
Public Member Functions | |
CircularBuffer (uint16_t capacity) | |
Default constructor. More... | |
virtual | ~CircularBuffer () |
Default destructor. More... | |
uint16_t | getMaxByteSize (uint16_t capacity) |
uint16_t | getMaxByteSize () |
uint16_t | getMaxSize (uint16_t byteSize) |
bool | init () |
Initializes and allocates memory for the buffer based on the capacity. More... | |
bool | deinit () |
bool | assign (buffer_ptr_t buffer, uint16_t bufferSize) |
Assign the buffer used to store the data, instead of allocating it via init(). More... | |
bool | release () |
Release the buffer that was assigned. More... | |
bool | isInitialized () |
Returns true when the buffer has been allocated, either via init() or via assign(). More... | |
T * | getBuffer () |
void | clear () |
Clears the buffer. More... | |
uint16_t | size () const |
Returns the number of elements stored. More... | |
uint16_t | capacity () const |
Returns the capacity of the buffer. More... | |
bool | empty () const |
Checks if the buffer is empty. More... | |
bool | full () const |
Checks if the buffer is full. More... | |
void | push (const T &value) |
Add an element to the end of the buffer. More... | |
bool | pushUnique (const T &value) |
Add an element to the end of the buffer, but only when it's not already in the buffer. More... | |
const T & | pop () |
Get the oldest element. More... | |
T & | peek () const |
Peek at the oldest element without removing it. More... | |
T & | operator[] (uint16_t idx) const |
Returns the Nth value, starting from oldest element. More... | |
uint16_t | find (const T &value) const |
Find a value in the buffer. More... | |
Private Member Functions | |
void | incTail () |
Increases the tail. More... | |
void | incHead () |
Increases the head. More... | |
Private Attributes | |
T * | _array |
Pointer to the array storing the elements. More... | |
uint16_t | _capacity |
The capacity of the buffer (maximum number of elements) More... | |
uint16_t | _head |
Index of the head (next element to be removed) More... | |
uint16_t | _tail |
Index of the tail (where the next element will be inserted) More... | |
uint16_t | _contentsSize |
Number of elements stored in the buffer. More... | |
bool | _allocatedSelf |
Whether the array was allocated by init() or not. More... | |
Circular Buffer implementation.
T | Element type of elements within the buffer. |
Elements are added at the back and removed from the front. If the capacity of the buffer is reached, the oldest element will be overwritten.
|
inline |
Default constructor.
|
inlinevirtual |
Default destructor.
|
inline |
Assign the buffer used to store the data, instead of allocating it via init().
@buffer The buffer to be used. @bufferSize Size of the buffer.
|
inline |
Returns the capacity of the buffer.
The capacity is the maximum number of elements that can be stored in the buffer
|
inline |
Clears the buffer.
The buffer is cleared by setting head and tail to the beginning of the buffer. The array itself doesn't have to be cleared
|
inline |
|
inline |
Checks if the buffer is empty.
|
inline |
Find a value in the buffer.
|
inline |
Checks if the buffer is full.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
Increases the head.
Decreases the contentsSize and increases the index of the head. It also wraps around the head if the end of the array is reached.
|
inlineprivate |
Increases the tail.
Increases the contentsSize and the index of the tail. It also wraps the tail around if the end of the array is reached.
|
inline |
Initializes and allocates memory for the buffer based on the capacity.
@capacity the number of elements that should be stored in this buffer, before overwriting the oldest element.
|
inline |
|
inline |
Returns the Nth value, starting from oldest element.
Does NOT check if you reached the end, make sure you read no more than size().
|
inline |
Peek at the oldest element without removing it.
This returns the value of the oldest element without removing the element from the buffer. Use <CircularBuffer>>pop()> to get the value and remove it at the same time
|
inline |
Get the oldest element.
This returns the value of the oldest element and removes it from the buffer
|
inline |
Add an element to the end of the buffer.
@value the element to be added
Elements are added at the end of the buffer and removed from the beginning. If the buffer is full the oldest element will be overwritten.
|
inline |
Add an element to the end of the buffer, but only when it's not already in the buffer.
|
inline |
Release the buffer that was assigned.
|
inline |
Returns the number of elements stored.
|
private |
Whether the array was allocated by init() or not.
|
private |
Pointer to the array storing the elements.
|
private |
The capacity of the buffer (maximum number of elements)
|
private |
Number of elements stored in the buffer.
|
private |
Index of the head (next element to be removed)
|
private |
Index of the tail (where the next element will be inserted)