| ECC1C 145-944-00

Public Types | Public Member Functions | List of all members
CircularBuffer< FixedSize >

## Public Types
enum |

## Public Member Functions
bool | Append (const uint8 *buf, uint16 len)
bool | Extract (uint8 *buffer, uint16 &len)
uint32 | getSize () const
uint32 | getAllocatedSize () const
uint32 | getFreeSize () const
void | getHeads (uint32 &readHead, uint32 &writeHead) const
bool | isFull ()
| CircularBuffer ()

## Detailed Description

template<size_t FixedSize>
class CircularBuffer< FixedSize >

A simple two head and size limited buffer AKA circular/ring buffer. This is used to store a contiguous stream of data, where the oldest item are discarded to store the new one.

Parameters

  FixedSize | The buffer size (should be a power of 2)

Warning
  The number of stored element in this array is exactly (size - 1). This is a bit clever as it stores the len of the added element in the array first

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum

Make the size accessible from outside this class too

## Constructor & Destructor Documentation

## ◆ CircularBuffer()

CircularBuffer | ( |  | ) |
| inline

Build a circular buffer for the specified size.

## Member Function Documentation

## ◆ Append()

bool Append | ( | const uint8 * | buf,
|  | uint16 | len
| ) |  |
| inline

Add some data to this buffer

References CircularBuffer< FixedSize >::getFreeSize().

Referenced by CommandParser::process().

## ◆ Extract()

bool Extract | ( | uint8 * | buffer,
|  | uint16 & | len
| ) |  |
| inline

Extract data from this buffer

References CircularBuffer< FixedSize >::getSize().

Referenced by CommandParser::parseCommand().

## ◆ getAllocatedSize()

uint32 getAllocatedSize | ( |  | ) | const
| inline

Get the allocated size for this buffer, in bytes

Referenced by CircularBuffer< FixedSize >::getFreeSize().

## ◆ getFreeSize()

uint32 getFreeSize | ( |  | ) | const
| inline

Get the free size in this buffer

References CircularBuffer< FixedSize >::getAllocatedSize(), and CircularBuffer< FixedSize >::getSize().

Referenced by CircularBuffer< FixedSize >::Append().

## ◆ getHeads()

void getHeads | ( | uint32 & | readHead,
|  | uint32 & | writeHead
| ) |  | const
| inline

Get the current buffer heads position (this can be used for making statistics about this buffer consumption)

## ◆ getSize()

uint32 getSize | ( |  | ) | const
| inline

Get the consumed size in the buffer in bytes

Referenced by CircularBuffer< FixedSize >::Extract(), and CircularBuffer< FixedSize >::getFreeSize().

## ◆ isFull()

bool isFull | ( |  | ) |
| inline

Check if the buffer is almost full.

Warning
  This buffer can't be completely full (one free spot is always available), so this method returns true when there is only 1 free spot left