Really simple fifo implementation. More...
#include <fifo.hpp>
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 |
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
T& ecl::FiFo< T >::operator[] | ( | int | idx | ) | [inline] |
const T& ecl::FiFo< T >::operator[] | ( | int | idx | ) | const [inline] |
Resize the fifo storage.
length | : new size. |
StandardException | : throws if a zero sized storage is specified. |
ecl::Array<T> ecl::FiFo< T >::data [private] |
unsigned int ecl::FiFo< T >::running_index [private] |