Public Member Functions | Private Attributes | List of all members
ecl::FiFo< T > Class Template Reference

Really simple fifo implementation. More...

#include <fifo.hpp>

Public Member Functions

 FiFo (const unsigned int length, const T &value)
 Initialise and fill the fifo. More...
 
 FiFo (const unsigned int length=0)
 Initialises the fifo, but does not fill it. More...
 
void fill (const T &value)
 One-shot fill method. More...
 
unsigned int get_idx ()
 Index of the oldest element in the fifo. More...
 
T & operator[] (int idx)
 Returns the indexed value offset from the oldest data. More...
 
const T & operator[] (int idx) const
 Const version of the [] accessor. More...
 
void push_back (const T &datum)
 Push back onto the fifo. More...
 
void resize (unsigned int length)
 Resize the fifo storage. More...
 

Private Attributes

ecl::Array< T > data
 
unsigned int running_index
 
unsigned int size_fifo
 

Detailed Description

template<typename T>
class ecl::FiFo< T >

Really simple fifo implementation.

For control programs, fifo is typically used for data storage, moving average and some applications. It uses ecl::Array internally for storage (all exception handling is thus handled by ecl::Array).

Usage:

During the construction of fifo, typically length of buffer may be important.

FiFo<double> fifo(4);
fifo.push_back( data_incoming );
But initial value for whole buffer can be important to you.
Especially if you want to use fifo for moving average,
you should wait for N (length of buffer) incoming of data.
But if you use below code, you can use fifo immediately
@code
FiFo<double> fifo(4, initial_value); // construct with initial value for whole buffer
fifo.push_back( next_data ); // set next data
... // calculate the average here

Data access

[0] always return oldest data set from the fifo and [N-1] returns always new data from the fifo once your buffer is full.

FiFo<double> fifo(4);
fifo.push_back(1.0);
fifo.push_back(2.0);
fifo.push_back(3.0);
fifo.push_back(4.0);
std::cout << fifo[0] << std::endl; // 1.0
std::cout << fifo[3] << std::endl; // 4.0
See also
ecl::Array.

Definition at line 88 of file fifo.hpp.

Constructor & Destructor Documentation

◆ FiFo() [1/2]

template<typename T >
ecl::FiFo< T >::FiFo ( const unsigned int  length = 0)
inline

Initialises the fifo, but does not fill it.

Parameters
length: size of the fifo.

Definition at line 103 of file fifo.hpp.

◆ FiFo() [2/2]

template<typename T >
ecl::FiFo< T >::FiFo ( const unsigned int  length,
const T &  value 
)
inline

Initialise and fill the fifo.

Parameters
length: the size of the fifo.
value: the constant to fill the fifo with.

Definition at line 117 of file fifo.hpp.

Member Function Documentation

◆ fill()

template<typename T >
void ecl::FiFo< T >::fill ( const T &  value)
inline

One-shot fill method.

Parameters
value: the constant value to fill with.

Definition at line 166 of file fifo.hpp.

◆ get_idx()

template<typename T >
unsigned int ecl::FiFo< T >::get_idx ( )
inline

Index of the oldest element in the fifo.

Returns
int : the index.

Definition at line 174 of file fifo.hpp.

◆ operator[]() [1/2]

template<typename T >
T& ecl::FiFo< T >::operator[] ( int  idx)
inline

Returns the indexed value offset from the oldest data.

This ensures that [0] returns always oldest data from the buffer, others will be offset from this.

Parameters
idx: index
Returns
T& : reference (modifiable) to the indexed element.

Definition at line 136 of file fifo.hpp.

◆ operator[]() [2/2]

template<typename T >
const T& ecl::FiFo< T >::operator[] ( int  idx) const
inline

Const version of the [] accessor.

Parameters
idx: index
Returns
const T& : const reference to the indexed element.

Definition at line 146 of file fifo.hpp.

◆ push_back()

template<typename T >
void ecl::FiFo< T >::push_back ( const T &  datum)
inline

Push back onto the fifo.

This will overwrite the oldest element in the fifo.

Parameters
datum: incoming value.

Definition at line 157 of file fifo.hpp.

◆ resize()

template<typename T >
void ecl::FiFo< T >::resize ( unsigned int  length)
inline

Resize the fifo storage.

Parameters
length: new size.
Exceptions
StandardException: throws if a zero sized storage is specified.

Definition at line 181 of file fifo.hpp.

Member Data Documentation

◆ data

template<typename T >
ecl::Array<T> ecl::FiFo< T >::data
private

Definition at line 188 of file fifo.hpp.

◆ running_index

template<typename T >
unsigned int ecl::FiFo< T >::running_index
private

Definition at line 190 of file fifo.hpp.

◆ size_fifo

template<typename T >
unsigned int ecl::FiFo< T >::size_fifo
private

Definition at line 189 of file fifo.hpp.


The documentation for this class was generated from the following file:
ecl::FiFo::data
ecl::Array< T > data
Definition: fifo.hpp:188


ecl_containers
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:34