event_detector 1.0.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DifferenceBasedBuffer< T, C, D > Class Template Reference

Ring-buffer-like container for keeping only values within a fixed range of a secondary index parameter. More...

#include <DifferenceBasedBuffer.hpp>

Inheritance diagram for DifferenceBasedBuffer< T, C, D >:

Public Member Functions

 DifferenceBasedBuffer (const D &diff=D(0, 0))
 Constructs a new DifferenceBasedBuffer object.
 
void setDifference (const D &diff)
 Sets new difference. Will affect subsequent calls to update().
 
void push_back (const T &val, const C &stamp=C())
 Adds new element to the end.
 
void push_front (const T &val, const C &stamp=C())
 Adds new element to the front.
 
void insert (typename StampedDeque< T, C >::const_iterator position, const T &val, const C &stamp=C())
 Adds new element at position.
 
T & operator[] (const int n)
 Accesses specified element.
 
const T & operator[] (const int n) const
 Accesses specified element.
 
T & at (const int n)
 Accesses specified element.
 
const T & at (const int n) const
 Accesses specified element.
 
std::pair< C, T > & get (const int n)
 Accesses specified element including stamp.
 
const std::pair< C, T > & get (const int n) const
 Accesses specified element including stamp.
 
T & front ()
 Accesses first element.
 
const T & front () const
 Accesses first element.
 
T & back ()
 Accesses last element.
 
const T & back () const
 Accesses last element.
 

Protected Member Functions

void update (const C &stamp)
 Removes all elements with stamps outside of (stamp - diff_, stamp].
 

Protected Attributes

diff_
 Difference value.
 

Detailed Description

template<typename T, typename C = int, typename D = C>
class DifferenceBasedBuffer< T, C, D >

Ring-buffer-like container for keeping only values within a fixed range of a secondary index parameter.

A DifferenceBasedBuffer is a special type of deque similar to a fixed length circular buffer. Instead of having a fixed length, the DifferenceBasedBuffer only keeps those values, whose secondary stamp value is within a fixed range of the most recently inserted value's stamp. As an example, a DifferenceBasedBuffer can thus be used for keeping all values with a stamp within the last 5 minutes by using timestamps as the secondary stamp argument upon insertion.

Template Parameters
Ttype of values to store
Ctype of secondary index parameter
Dtype of secondary index parameter range (C-C)

Definition at line 57 of file DifferenceBasedBuffer.hpp.

Constructor & Destructor Documentation

◆ DifferenceBasedBuffer()

template<typename T , typename C = int, typename D = C>
DifferenceBasedBuffer< T, C, D >::DifferenceBasedBuffer ( const D &  diff = D(0, 0))

Constructs a new DifferenceBasedBuffer object.

Parameters
difffixed range from most recent stamp within which values are kept in the buffer

Member Function Documentation

◆ at() [1/2]

template<typename T , typename C = int, typename D = C>
T & DifferenceBasedBuffer< T, C, D >::at ( const int  n)

Accesses specified element.

Parameters
nindex of requested element
Returns
T& reference to requested element

◆ at() [2/2]

template<typename T , typename C = int, typename D = C>
const T & DifferenceBasedBuffer< T, C, D >::at ( const int  n) const

Accesses specified element.

Parameters
nindex of requested element
Returns
const T& reference to requested element

◆ back() [1/2]

template<typename T , typename C = int, typename D = C>
T & DifferenceBasedBuffer< T, C, D >::back ( )

Accesses last element.

Returns
T& reference to last element

◆ back() [2/2]

template<typename T , typename C = int, typename D = C>
const T & DifferenceBasedBuffer< T, C, D >::back ( ) const

Accesses last element.

Returns
const T& reference to last element

◆ front() [1/2]

template<typename T , typename C = int, typename D = C>
T & DifferenceBasedBuffer< T, C, D >::front ( )

Accesses first element.

Returns
T& reference to first element

◆ front() [2/2]

template<typename T , typename C = int, typename D = C>
const T & DifferenceBasedBuffer< T, C, D >::front ( ) const

Accesses first element.

Returns
const T& reference to first element

◆ get() [1/2]

template<typename T , typename C = int, typename D = C>
std::pair< C, T > & DifferenceBasedBuffer< T, C, D >::get ( const int  n)

Accesses specified element including stamp.

Parameters
nindex of requested element
Returns
std::pair<C, T>& reference to requested pair

◆ get() [2/2]

template<typename T , typename C = int, typename D = C>
const std::pair< C, T > & DifferenceBasedBuffer< T, C, D >::get ( const int  n) const

Accesses specified element including stamp.

Parameters
nindex of requested element
Returns
const std::pair<C, T>& reference to requested pair

◆ insert()

template<typename T , typename C = int, typename D = C>
void DifferenceBasedBuffer< T, C, D >::insert ( typename StampedDeque< T, C >::const_iterator  position,
const T &  val,
const C &  stamp = C() 
)

Adds new element at position.

All elements with stamps outside (stamp - diff_, stamp] will be removed.

Parameters
positioniterator before which the element will be inserted
valnew value to add
stampstamp of new element

◆ operator[]() [1/2]

template<typename T , typename C = int, typename D = C>
T & DifferenceBasedBuffer< T, C, D >::operator[] ( const int  n)

Accesses specified element.

Parameters
nindex of requested element
Returns
T& reference to requested element

◆ operator[]() [2/2]

template<typename T , typename C = int, typename D = C>
const T & DifferenceBasedBuffer< T, C, D >::operator[] ( const int  n) const

Accesses specified element.

Parameters
nindex of requested element
Returns
const T& reference to requested element

◆ push_back()

template<typename T , typename C = int, typename D = C>
void DifferenceBasedBuffer< T, C, D >::push_back ( const T &  val,
const C &  stamp = C() 
)

Adds new element to the end.

All elements with stamps outside (stamp - diff_, stamp] will be removed.

Parameters
valnew value to add
stampstamp of new element

◆ push_front()

template<typename T , typename C = int, typename D = C>
void DifferenceBasedBuffer< T, C, D >::push_front ( const T &  val,
const C &  stamp = C() 
)

Adds new element to the front.

All elements with stamps outside (stamp - diff_, stamp] will be removed.

Parameters
valnew value to add
stampstamp of new element

◆ update()

template<typename T , typename C = int, typename D = C>
void DifferenceBasedBuffer< T, C, D >::update ( const C &  stamp)
protected

Removes all elements with stamps outside of (stamp - diff_, stamp].

Parameters
stampupper bound of range within which to keep values

Member Data Documentation

◆ diff_

template<typename T , typename C = int, typename D = C>
D DifferenceBasedBuffer< T, C, D >::diff_
protected

Difference value.

Used for removing elements when the difference between their stamp value the newest stamp value is greater than this difference value.

Definition at line 199 of file DifferenceBasedBuffer.hpp.


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