semf
semf::RingBuffer< T > Class Template Reference

The RingBuffer class implements a classic circular buffer. More...

#include <ringbuffer.h>

Inheritance diagram for semf::RingBuffer< T >:
Inheritance graph
Collaboration diagram for semf::RingBuffer< T >:
Collaboration graph

Public Member Functions

virtual void put (T data)
 Writes data in the buffer. More...
 
T & get ()
 Returns the oldest value not read yet. More...
 
virtual T & operator[] (size_t pos) const
 Returns the entry from a specific position in the buffer. More...
 
bool isFull () const
 Returns if the buffer is full. More...
 
bool isEmpty () const
 Returns if the buffer is empty. More...
 
size_t count () const override
 Returns the number of entries stored in the buffer and not read yet. More...
 
void reset ()
 Clears the buffer. More...
 
- Public Member Functions inherited from semf::Buffer< T >
 Buffer ()=default
 
 Buffer (T buffer[], size_t bufferSize)
 Constructor with data array initialization. More...
 
virtual ~Buffer ()=default
 
void setBuffer (T buffer[], size_t bufferSize)
 Sets the data array. More...
 
virtual T & operator[] (size_t pos) const
 Returns the entry from a specific position in the buffer. More...
 
size_t size () const
 Returns the size of the buffer. More...
 
virtual size_t count () const
 Returns the number of entries stored in the buffer. More...
 
T * data () const
 Returns the pointer to the first element of the data array. More...
 

Detailed Description

template<typename T>
class semf::RingBuffer< T >

The RingBuffer class implements a classic circular buffer.

The data base is an array with the data type defined by the template parameter T. To use the RingBuffer set the array in the constructor or by the function setData().

The data can be accessed by the functions

  • data() to get the pointer to the data array,
  • at() to get the element on a specific position and
  • get() to get the oldest entry not read jet.

The data can be stored in the buffer by the function put().

See also Buffer, LastInBuffer, LastInDmaBuffer and Average.

Note
For using RingBuffer a global CriticalSection object is required.
Attention
If USE_SEMF_DEBUG is defined RingBuffer uses nullptr dereferencing instead of an error signal.
Template Parameters
Typeof data to handle.

Definition at line 39 of file ringbuffer.h.

Member Function Documentation

◆ count()

template<typename T >
size_t semf::RingBuffer< T >::count
overridevirtual

Returns the number of entries stored in the buffer and not read yet.

Returns
Number of entries.

Reimplemented from semf::Buffer< T >.

Definition at line 180 of file ringbuffer.h.

Here is the call graph for this function:

◆ get()

template<typename T >
T & semf::RingBuffer< T >::get

Returns the oldest value not read yet.

Returns
Oldest entry not read yet.
Note
Using this function while USE_SEMF_DEBUG or DEBUG being defined will cause a boundary check. In case of failing the boundary check the function will dereference a nullptr in order to crash the software forcefully.

Definition at line 114 of file ringbuffer.h.

Here is the call graph for this function:

◆ isEmpty()

template<typename T >
bool semf::RingBuffer< T >::isEmpty

Returns if the buffer is empty.

Note
If the buffer is empty, use put() before put().
Returns
  • true: No unread data available.
  • false: Unread data available.

Definition at line 166 of file ringbuffer.h.

Here is the call graph for this function:

◆ isFull()

template<typename T >
bool semf::RingBuffer< T >::isFull

Returns if the buffer is full.

Note
If the buffer is full use get() to free a buffer entry place before put().
Returns
  • true: Buffer array is full.
  • false: Buffer array is has still free space.

Definition at line 153 of file ringbuffer.h.

Here is the call graph for this function:

◆ operator[]()

template<typename T >
T & semf::RingBuffer< T >::operator[] ( size_t  pos) const
virtual

Returns the entry from a specific position in the buffer.

Parameters
posPosition in the buffer.
Returns
Entry.
Note
Using this function while USE_SEMF_DEBUG or DEBUG being defined will cause a boundary check. In case of failing the boundary check the function will dereference a nullptr in order to crash the software forcefully.

Reimplemented from semf::Buffer< T >.

Definition at line 134 of file ringbuffer.h.

Here is the call graph for this function:

◆ put()

template<typename T >
void semf::RingBuffer< T >::put ( data)
virtual

Writes data in the buffer.

Parameters
dataData to write into the buffer into the next free space.

Definition at line 99 of file ringbuffer.h.

Here is the call graph for this function:

◆ reset()

template<typename T >
void semf::RingBuffer< T >::reset

Clears the buffer.

Note
The data in the base array will not be modified.

Definition at line 190 of file ringbuffer.h.

Here is the call graph for this function: