Mbed OS Reference
Loading...
Searching...
No Matches
CircularBuffer< T, BufferSize, CounterType > Class Template Reference

Templated Circular buffer class. More...

#include <CircularBuffer.h>

Public Member Functions

void push (const T &data)
 Push the transaction to the buffer. More...
 
void push (const T *src, CounterType len)
 Push the transaction to the buffer. More...
 
void push (mbed::Span< const T > src)
 Push the transaction to the buffer. More...
 
bool pop (T &data)
 Pop from the buffer. More...
 
CounterType pop (T *dest, CounterType len)
 Pop multiple elements from the buffer. More...
 
mbed::Span< T > pop (mbed::Span< T > dest)
 Pop multiple elements from the buffer. More...
 
bool empty () const
 Check if the buffer is empty. More...
 
bool full () const
 Check if the buffer is full. More...
 
void reset ()
 Reset the buffer. More...
 
CounterType size () const
 Get the number of elements currently stored in the circular_buffer. More...
 
bool peek (T &data) const
 Peek into circular buffer without popping. More...
 

Detailed Description

template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
class mbed::CircularBuffer< T, BufferSize, CounterType >

Templated Circular buffer class.

Note
Synchronization level: Interrupt safe.
CounterType must be unsigned and consistent with BufferSize.

Definition at line 69 of file CircularBuffer.h.

Member Function Documentation

◆ push() [1/3]

void push ( const T &  data)

Push the transaction to the buffer.

This overwrites the buffer if it's full.

Parameters
dataData to be pushed to the buffer.

Definition at line 93 of file CircularBuffer.h.

◆ push() [2/3]

void push ( const T *  src,
CounterType  len 
)

Push the transaction to the buffer.

This overwrites the buffer if it's full.

Parameters
srcData to be pushed to the buffer.
lenNumber of items to be pushed to the buffer.

Definition at line 115 of file CircularBuffer.h.

◆ push() [3/3]

void push ( mbed::Span< const T >  src)

Push the transaction to the buffer.

This overwrites the buffer if it's full.

Parameters
srcData to be pushed to the buffer.

Definition at line 162 of file CircularBuffer.h.

◆ pop() [1/3]

bool pop ( T &  data)

Pop from the buffer.

Parameters
dataContainer to store the data to be popped from the buffer.
Returns
True if data popped.

Definition at line 172 of file CircularBuffer.h.

◆ pop() [2/3]

CounterType pop ( T *  dest,
CounterType  len 
)

Pop multiple elements from the buffer.

Parameters
destThe array which will receive the elements.
lenThe number of elements to pop.
Returns
The number of elements popped.

Definition at line 199 of file CircularBuffer.h.

◆ pop() [3/3]

mbed::Span< T > pop ( mbed::Span< T >  dest)

Pop multiple elements from the buffer.

Parameters
destThe span that contains the buffer that will be used to store the elements.
Returns
The span with the size set to number of elements popped using the buffer passed in as the parameter.

Definition at line 251 of file CircularBuffer.h.

◆ empty()

bool empty ( ) const

Check if the buffer is empty.

Returns
True if the buffer is empty, false if not.

Definition at line 261 of file CircularBuffer.h.

◆ full()

bool full ( ) const

Check if the buffer is full.

Returns
True if the buffer is full, false if not

Definition at line 273 of file CircularBuffer.h.

◆ reset()

void reset ( )

Reset the buffer.

Definition at line 281 of file CircularBuffer.h.

◆ size()

CounterType size ( ) const

Get the number of elements currently stored in the circular_buffer.

Definition at line 293 of file CircularBuffer.h.

◆ peek()

bool peek ( T &  data) const

Peek into circular buffer without popping.

Parameters
dataData to be peeked from the buffer.
Returns
True if the buffer is not empty and data contains a transaction, false otherwise.

Definition at line 306 of file CircularBuffer.h.