Public Member Functions | Private Attributes
ecl::FiFo< T > Class Template Reference

Really simple fifo implementation. More...

#include <fifo.hpp>

List of all members.

Public Member Functions

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

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 82 of file fifo.hpp.


Constructor & Destructor Documentation

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 89 of file fifo.hpp.

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 103 of file fifo.hpp.

template<typename T>
virtual ecl::FiFo< T >::~FiFo ( ) [inline, virtual]

Default destructor.

Definition at line 111 of file fifo.hpp.


Member Function Documentation

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 152 of file fifo.hpp.

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 160 of file fifo.hpp.

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 122 of file fifo.hpp.

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 132 of file fifo.hpp.

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 143 of file fifo.hpp.

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 167 of file fifo.hpp.


Member Data Documentation

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

Definition at line 174 of file fifo.hpp.

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

Definition at line 176 of file fifo.hpp.

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

Definition at line 175 of file fifo.hpp.


The documentation for this class was generated from the following file:


ecl_containers
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:43