semf
semf::Buffer< T > Class Template Reference

Buffer is a base class for buffer implementations. More...

#include <buffer.h>

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

Public Member Functions

 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::Buffer< T >

Buffer is a base class for buffer implementations.

The data base is an array with the data type defined by the template parameter T. To use the Buffer 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 and
  • at() to get the element on a specific position.

Buffer itself has no function to put data in the buffer.

See also RingBuffer, LastInBuffer, LastInDmaBuffer and Average.

Note
For using RingBuffer a global CriticalSection object is required.
Attention
If USE_SEMF_DEBUG or DEBUG is defined Buffer uses nullptr dereferencing instead of an error signal.
Template Parameters
TData type

Definition at line 41 of file buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/2]

template<typename T >
semf::Buffer< T >::Buffer ( )
default

◆ Buffer() [2/2]

template<typename T >
semf::Buffer< T >::Buffer ( buffer[],
size_t  bufferSize 
)

Constructor with data array initialization.

Parameters
bufferPointer to the array to store data in.
bufferSizeThe size of the data array.

Definition at line 92 of file buffer.h.

◆ ~Buffer()

template<typename T >
virtual semf::Buffer< T >::~Buffer ( )
virtualdefault

Member Function Documentation

◆ count()

template<typename T >
size_t semf::Buffer< T >::count
virtual

Returns the number of entries stored in the buffer.

Note
In this basic implementation count() returns size().
Returns
Number of entries.

Reimplemented in semf::LastInDmaBuffer< T >, and semf::RingBuffer< T >.

Definition at line 133 of file buffer.h.

Here is the caller graph for this function:

◆ data()

template<typename T >
T * semf::Buffer< T >::data

Returns the pointer to the first element of the data array.

Returns
Pointer to the data array.

Definition at line 139 of file buffer.h.

Here is the caller graph for this function:

◆ operator[]()

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

Returns the entry from a specific position in the buffer.

Parameters
posPosition in the buffer.
Returns
Data 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 in semf::LastInBuffer< T >, semf::LastInDmaBuffer< T >, and semf::RingBuffer< T >.

Definition at line 111 of file buffer.h.

Here is the call graph for this function:

◆ setBuffer()

template<typename T >
void semf::Buffer< T >::setBuffer ( buffer[],
size_t  bufferSize 
)

Sets the data array.

Parameters
bufferPointer to the array to store data in.
bufferSizeThe size of the data array.

Definition at line 99 of file buffer.h.

Here is the call graph for this function:

◆ size()

template<typename T >
size_t semf::Buffer< T >::size

Returns the size of the buffer.

Returns
Buffer size.

Definition at line 127 of file buffer.h.

Here is the caller graph for this function: