NMEA2000 Library
0.1
Library to handle NMEA 2000 Communication written in C++
|
Template Class that holds values with given priorities in a ring buffer. More...
#include <RingBuffer.h>
Classes | |
struct | tPriorityRef |
Structure handles meta data for each priority. More... | |
struct | tValueSlot |
Structure that holds the actual value and meta data. More... | |
Public Member Functions | |
tPriorityRingBuffer (uint16_t _size, uint8_t _maxPriorities=1) | |
Construct a new Priority ring buffer object. More... | |
virtual | ~tPriorityRingBuffer () |
Destroy the priority ring buffer object Frees all memory. More... | |
bool | add (const T &val, uint8_t _priority=0) |
Add a value to the ring buffer with a given priority. More... | |
void | clean () |
This function does nothing at the moment! More... | |
void | clear () |
Clears the whole ring buffer. More... | |
uint16_t | count () |
Returns the number of values in the ring buffer. More... | |
T * | getAddRef (uint8_t _priority=0) |
Get the pointer to new value added to the ring buffer. More... | |
const T * | getReadRef (uint8_t *_priority=0) |
Get pointer to highest priority value read out from the the ring buffer. More... | |
const T * | getReadRef (uint8_t _priority) |
Get the pointer to value with given priority read out from the ring buffer. More... | |
uint16_t | getSize () const |
Get the size of the ring buffer. More... | |
bool | isEmpty (uint8_t _priority=0xff) const |
Check is ring buffer empty. More... | |
bool | read (T &val) |
Reads highest priority value out from the ring buffer. More... | |
Static Public Member Functions | |
static uint32_t | getMemSize (uint16_t _size, uint8_t _maxPriorities=1) |
Get the size of memory required by ring buffer. More... | |
Protected Attributes | |
tValueSlot * | buffer |
Pointer to the ring puffer in memory. More... | |
uint16_t | head |
Index of the first free index in the ring buffer. More... | |
uint8_t | maxPriorities |
highest priority possible More... | |
tPriorityRef * | priorityReferencies |
Pointer to priority references in buffer. More... | |
uint16_t | size |
Number of values that can be stored in the ring buffer. More... | |
uint16_t | tail |
Index of the last occupied index in the ring buffer. More... | |
Template Class that holds values with given priorities in a ring buffer.
tPriorityRingBuffer is similar as tRingBuffer, but it extends functionality with value priority. When you add values to the buffer, you can give them priority. When you read them out you can get highest priority or request specific priority value.
The advantage of tPriorityRingBuffer is that it will reserve one continuous block for all priorities instead of reserve one buffer for each priority.
T | Template used for the class |
Definition at line 255 of file RingBuffer.h.
tPriorityRingBuffer< T >::tPriorityRingBuffer | ( | uint16_t | _size, |
uint8_t | _maxPriorities = 1 |
||
) |
Construct a new Priority ring buffer object.
Allocates all the memory needed, initialize attributes and priorities.
_size | Size of the ring buffer |
_maxPriorities | highest priority possible |
|
virtual |
Destroy the priority ring buffer object Frees all memory.
bool tPriorityRingBuffer< T >::add | ( | const T & | val, |
uint8_t | _priority = 0 |
||
) |
Add a value to the ring buffer with a given priority.
val | Value to be added |
_priority | Priority for the added value (default = 0) |
true | Add succeeded |
false | Buffer is full |
void tPriorityRingBuffer< T >::clean | ( | ) |
This function does nothing at the moment!
void tPriorityRingBuffer< T >::clear | ( | ) |
Clears the whole ring buffer.
uint16_t tPriorityRingBuffer< T >::count | ( | ) |
Returns the number of values in the ring buffer.
Currently function returns simple buffer count instead of true value count. Priority ring buffer may have values released between other values.
uint16_t | Number of values in buffer |
T * tPriorityRingBuffer< T >::getAddRef | ( | uint8_t | _priority = 0 | ) |
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.
_priority | Priority for the value (default = 0) |
T * | Pointer to added new value |
0 | Buffer is full |
|
static |
Get the size of memory required by ring buffer.
This is static function and can be used to test how much ring buffer would require memory with given size and count of priorities. Function can be used e.g., for checking available memory or possible memory "bank" handling.
const T * tPriorityRingBuffer< T >::getReadRef | ( | uint8_t * | _priority = 0 | ) |
Get pointer to highest priority value read out from the 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.
*_priority | Pointer to priority, which will be set to priority of the value read out. |
const T* | Pointer to value read out from the ring buffer |
0 | No values available. |
const T * tPriorityRingBuffer< T >::getReadRef | ( | uint8_t | _priority | ) |
Get the pointer to value with given priority 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.
_priority | Priority for the value read out |
const T* | Pointer to value read out from the ring buffer |
0 | No values available with given priority |
|
inline |
Get the size of the ring buffer.
uint16_t | Size of ring buffer |
Definition at line 326 of file RingBuffer.h.
bool tPriorityRingBuffer< T >::isEmpty | ( | uint8_t | _priority = 0xff | ) | const |
Check is ring buffer empty.
Result depends of _priority parameter. If valid priority within initial _maxPriorities is provided, function returns empty state of given priority. Otherwise it returns empty state of whole buffer.
_priority | Which buffer |
bool | Buffer empty state |
bool tPriorityRingBuffer< T >::read | ( | T & | val | ) |
Reads highest priority value out from the ring buffer.
val | Reference to the value read out from buffer |
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. |
|
protected |
Pointer to the ring puffer in memory.
Definition at line 294 of file RingBuffer.h.
|
protected |
Index of the first free index in the ring buffer.
Definition at line 298 of file RingBuffer.h.
|
protected |
highest priority possible
Definition at line 304 of file RingBuffer.h.
|
protected |
Pointer to priority references in buffer.
Definition at line 296 of file RingBuffer.h.
|
protected |
Number of values that can be stored in the ring buffer.
Definition at line 302 of file RingBuffer.h.
|
protected |
Index of the last occupied index in the ring buffer.
Definition at line 300 of file RingBuffer.h.