Template Class that holds values in a ring buffer.
More...
#include <RingBuffer.h>
|
| tRingBuffer (uint16_t _size) |
| Construct a new ring buffer object. More...
|
|
virtual | ~tRingBuffer () |
| Destroy the ring buffer object. More...
|
|
bool | add (const T &val) |
| Adds a new value to the ring buffer. More...
|
|
void | clear () |
| Clears the whole ring buffer. More...
|
|
uint16_t | count () |
| Returns the number of values in the ring buffer. More...
|
|
T * | getAddRef () |
| Get the pointer to new value added to the ring buffer. More...
|
|
const T * | getReadRef () |
| Get the pointer to value read out from the ring buffer. More...
|
|
uint16_t | getSize () const |
| Get the size of the ring buffer. More...
|
|
bool | isEmpty () const |
| Checks if the ring buffer is empty. More...
|
|
T * | peek () |
| Get pointer to next value to be read out from the ring buffer. Function does not read value out from the ring buffer. More...
|
|
bool | read (T &val) |
| Reads a value out from the ring buffer. More...
|
|
|
T * | buffer |
| Pointer to the ring buffer of values in memory. More...
|
|
uint16_t | head |
| Index of the first value in the ring buffer. More...
|
|
uint16_t | size |
| Number of values that can be stored in the ring buffer. More...
|
|
uint16_t | tail |
| Index of the last value in the ring buffer. More...
|
|
template<typename T>
class tRingBuffer< T >
Template Class that holds values in a ring buffer.
With tRingBuffer one can save values to a ring buffer. Value can be simple value or data structure.
- Note
- You have to take care of data locking from other threads or interrupts around calls using buffer handling routines.
- See also
-
- Template Parameters
-
T | Template used for the class |
Definition at line 113 of file RingBuffer.h.
◆ tRingBuffer()
Construct a new ring buffer object.
A buffer with the corresponding size of values will be allocated to the memory.
- Parameters
-
_size | Size of the ring buffer |
◆ ~tRingBuffer()
Destroy the ring buffer object.
All memory will be freed
◆ add()
Adds a new value to the ring buffer.
- See also
-
- Parameters
-
- Return values
-
true | Add succeeded |
false | Buffer is full |
◆ clear()
Clears the whole ring buffer.
◆ count()
Returns the number of values in the ring buffer.
- Return values
-
uint16_t | Number of values in the ring buffer |
◆ getAddRef()
Get the pointer to new value added to the ring buffer.
Using getAddRef instead of add saves data copying between values. By using add, one must first setup value, which will be then copied to buffer within add. By using getAddRef one can request pointer to next buffer value and copy data directly to it.
- Note
- In multitasking or with interrupts one must take care that buffer will no be used before data handling has been finished. This differs from add, where it is enough to use locking only around calling add.
- Return values
-
T * | Pointer to added new value |
0 | Buffer is full |
◆ getReadRef()
Get the pointer to value read out from the ring buffer.
Using getReadRef instead of read saves data copying between values. By using read data will be copied to value, which one then may forward elsewhere. By using getReadRef one can request pointer to value and forward data directly from it.
- Note
- In multitasking or with interrupts one must take care that buffer will no be used before data handling has been finished. This differs from read, where it is enough to use locking only around calling read.
- Return values
-
const T* | Pointer to value read out from the ring buffer |
0 | No values available |
◆ getSize()
Get the size of the ring buffer.
- Return values
-
uint16_t | size of ring buffer |
Definition at line 144 of file RingBuffer.h.
◆ isEmpty()
Checks if the ring buffer is empty.
- Return values
-
true | Buffer is empty |
false | Buffer has data |
◆ peek()
Get pointer to next value to be read out from the ring buffer. Function does not read value out from the ring buffer.
- Return values
-
const T* | Pointer to value, which would be next read out from the ring buffer |
0 | No values available, buffer is empty. |
◆ read()
Reads a value out from the ring buffer.
- See also
-
- Parameters
-
val | Reference to the value read out from the ring buffer |
- Return values
-
true | Value read out from buffer. Value has been copied to parameter val |
false | There is no data available inside the buffer. Parameter val will be unchanged. |
◆ buffer
Pointer to the ring buffer of values in memory.
Definition at line 117 of file RingBuffer.h.
◆ head
Index of the first value in the ring buffer.
Definition at line 119 of file RingBuffer.h.
◆ size
Number of values that can be stored in the ring buffer.
Definition at line 123 of file RingBuffer.h.
◆ tail
Index of the last value in the ring buffer.
Definition at line 121 of file RingBuffer.h.
The documentation for this class was generated from the following file: