BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
bst::ConsecutiveValuesFilter< T > Class Template Reference

A simple counting filter that allows for some noise. More...

#include <filters.hpp>

Collaboration diagram for bst::ConsecutiveValuesFilter< T >:

Public Member Functions

 ConsecutiveValuesFilter (T initial_value, size_t filter_threshold=0)
 Constructor for the ConsecutiveValuesFilter. More...
 
 ~ConsecutiveValuesFilter ()=default
 Destructor for the ConsecutiveValuesFilter. More...
 
bool addValue (T value)
 The input stream for this filter. More...
 
getCurrentValue () const
 Returns the current value. More...
 
void reset (T value)
 Resets the filter's counter and sets the current value. More...
 
void setFilterThreshold (size_t filter_threshold)
 

Private Attributes

size_t current_count_ {0}
 The current count of consecutive new values. More...
 
current_value_ {}
 The current value. More...
 
size_t filter_threshold_
 The filter threshold. More...
 
new_value_ {}
 The new value that is being counted. More...
 

Detailed Description

template<class T>
class bst::ConsecutiveValuesFilter< T >

A simple counting filter that allows for some noise.

Template Parameters
TThe type of data to filter (enumerations generally).

Constructor & Destructor Documentation

◆ ConsecutiveValuesFilter()

template<class T >
bst::ConsecutiveValuesFilter< T >::ConsecutiveValuesFilter ( initial_value,
size_t  filter_threshold = 0 
)
inline

Constructor for the ConsecutiveValuesFilter.

Parameters
initial_valueThe initial value to set the filter to.
filter_thresholdThe number of consecutive values that must be seen before the filter will pass the value.

◆ ~ConsecutiveValuesFilter()

template<class T >
bst::ConsecutiveValuesFilter< T >::~ConsecutiveValuesFilter ( )
default

Destructor for the ConsecutiveValuesFilter.

Member Function Documentation

◆ reset()

template<class T >
void bst::ConsecutiveValuesFilter< T >::reset ( value)
inline

Resets the filter's counter and sets the current value.

Parameters
valueThe value to set the current value to.

References bst::ConsecutiveValuesFilter< T >::current_count_, and bst::ConsecutiveValuesFilter< T >::current_value_.

◆ setFilterThreshold()

template<class T >
void bst::ConsecutiveValuesFilter< T >::setFilterThreshold ( size_t  filter_threshold)
inline

◆ addValue()

template<class T >
bool bst::ConsecutiveValuesFilter< T >::addValue ( value)
inline

The input stream for this filter.

Parameters
valueThe input
Returns
true if the filtered value has changed, false otherwise.

References bst::ConsecutiveValuesFilter< T >::current_count_, bst::ConsecutiveValuesFilter< T >::current_value_, bst::ConsecutiveValuesFilter< T >::filter_threshold_, and bst::ConsecutiveValuesFilter< T >::new_value_.

◆ getCurrentValue()

template<class T >
T bst::ConsecutiveValuesFilter< T >::getCurrentValue ( ) const
inline

Returns the current value.

References bst::ConsecutiveValuesFilter< T >::current_value_.

Member Data Documentation

◆ filter_threshold_

template<class T >
size_t bst::ConsecutiveValuesFilter< T >::filter_threshold_
private

◆ current_count_

template<class T >
size_t bst::ConsecutiveValuesFilter< T >::current_count_ {0}
private

The current count of consecutive new values.

Referenced by bst::ConsecutiveValuesFilter< T >::addValue(), and bst::ConsecutiveValuesFilter< T >::reset().

◆ current_value_

◆ new_value_

template<class T >
T bst::ConsecutiveValuesFilter< T >::new_value_ {}
private

The new value that is being counted.

Referenced by bst::ConsecutiveValuesFilter< T >::addValue().