Hopsan
DelayTemplate< T > Class Template Reference

Delay template class, implementing a circular buffer containing values of specified type. More...

#include <Delay.hpp>

Public Member Functions

void initialize (const double timeDelay, const double Ts, const T initValue)
 Initialize delay buffer size based on timeDelay and timestep, Td/Ts must be multiple of 1 and >= 1.
 
void initialize (const int delaySteps, const T initValue)
 Initialize delay size based on known number of delay steps.
 
T update (const T newValue)
 Updates delay with a new value, "pop old", "push new". You should likely run this at the end of each time step.
 
T getOldest () const
 Get the oldest value in the buffer.
 
T getNewest () const
 Get the newest value in the buffer.
 
T getIdx (const size_t i) const
 Returns a specific value, 0=newest, 1=nextnewest, 2=nextnextnewest and so on, no range check is performed.
 
T getOldIdx (const size_t i) const
 Returns a specific value, 0=oldest, 1=nextoldest, 2=nextnextoldest and so on, no range check is performed.
 
size_t getSize () const
 Get the size of the delay buffer (the number of buffer elements)
 
void clear ()
 Clear the delay buffer, deleting all data.
 

Detailed Description

template<typename T>
class hopsan::DelayTemplate< T >

Delay template class, implementing a circular buffer containing values of specified type.

Member Function Documentation

◆ getIdx()

template<typename T >
T getIdx ( const size_t i) const
inline

Returns a specific value, 0=newest, 1=nextnewest, 2=nextnextnewest and so on, no range check is performed.

Parameters
[in]iIndex of value to return
Returns
Value at specified index

◆ getNewest()

template<typename T >
T getNewest ( ) const
inline

Get the newest value in the buffer.

Returns
The newest value in the buffer

◆ getOldest()

template<typename T >
T getOldest ( ) const
inline

Get the oldest value in the buffer.

Returns
The oldest value in the buffer

◆ getOldIdx()

template<typename T >
T getOldIdx ( const size_t i) const
inline

Returns a specific value, 0=oldest, 1=nextoldest, 2=nextnextoldest and so on, no range check is performed.

Parameters
[in]iIndex of value to return
Returns
Value at specified index

◆ getSize()

template<typename T >
size_t getSize ( ) const
inline

Get the size of the delay buffer (the number of buffer elements)

Returns
The size of the delay buffer

◆ initialize() [1/2]

template<typename T >
void initialize ( const double timeDelay,
const double Ts,
const T initValue )
inline

Initialize delay buffer size based on timeDelay and timestep, Td/Ts must be multiple of 1 and >= 1.

Parameters
[in]timeDelayThe total time delay for a value to come out on the other side of the circle buffer
[in]TsThe timestep between each call
[in]initValueThe initial value of all buffer elements

◆ initialize() [2/2]

template<typename T >
void initialize ( const int delaySteps,
const T initValue )
inline

Initialize delay size based on known number of delay steps.

Parameters
[in]delayStepsThe number of delay steps, must be >= 1
[in]initValueThe initial value of all buffer elements

◆ update()

template<typename T >
T update ( const T newValue)
inline

Updates delay with a new value, "pop old", "push new". You should likely run this at the end of each time step.

Parameters
[in]newValueThe new value to insert into delay buffer
Returns
The oldest value in the delay buffer (After update, this value has been overwritten in the buffer)