SoftFilters  0.1.0
Arduino framework and library of software data filters.
CachedFilter< IN_T, OUT_T > Class Template Referenceabstract

A filter with a data cache, which is suitable for output that depends on several previous input data. More...

#include <SoftFilters.h>

Inheritance diagram for CachedFilter< IN_T, OUT_T >:
Collaboration diagram for CachedFilter< IN_T, OUT_T >:

Public Member Functions

 CachedFilter (size_t cap)
 
- Public Member Functions inherited from Filter
bool push (void const *const input, void *const output)
 Push a new data through the filter. More...
 

Protected Member Functions

virtual bool update (void const *const input) override
 Internally update the filter output based on the given input. More...
 
virtual bool refresh (IN_T const *const new_val, IN_T const *const old_val, OUT_T &output)=0
 Refresh the output value given the new value added to the cache and the old value removed from the cache. More...
 
size_t get_capacity ()
 
size_t get_size ()
 
- Protected Member Functions inherited from BaseFilter< IN_T, OUT_T >
virtual void const *const get_output_val_ptr () final
 Push a new data through the filter. More...
 
virtual void copy_to_client (void *const output) final
 Copy the output to client memory.
 

Private Attributes

size_t capacity
 The cache capacity, i.e., maximum data it can hold.
 
size_t size
 The current cache size, i.e., valid data.
 
IN_T * buffer
 The internal buffer that holds the cached data.
 
int end
 The position in the internal buffer that points to the end of the cache. More...
 
IN_T cached_val
 used to temporarily store the old data before overwritten by the new data
 

Additional Inherited Members

- Protected Attributes inherited from BaseFilter< IN_T, OUT_T >
OUT_T out_val
 Internally managed storage of the output value.
 

Detailed Description

template<typename IN_T, typename OUT_T>
class CachedFilter< IN_T, OUT_T >

A filter with a data cache, which is suitable for output that depends on several previous input data.

This class is internally implemented as a circular buffer.

Template Parameters
IN_Tinput data type
OUT_Toutput data type

Member Function Documentation

◆ refresh()

template<typename IN_T , typename OUT_T >
virtual bool CachedFilter< IN_T, OUT_T >::refresh ( IN_T const *const  new_val,
IN_T const *const  old_val,
OUT_T &  output 
)
protectedpure virtual

Refresh the output value given the new value added to the cache and the old value removed from the cache.

Note
To be differentiated from the CachedFilter::update member function which overrides the BaseFilter::update member function.

Implemented in MovingVarianceFilter< IN_T, OUT_T, INTERNAL_T >, and MovingAverageFilter< IN_T, OUT_T, INTERNAL_T >.

◆ update()

template<typename IN_T , typename OUT_T >
virtual bool CachedFilter< IN_T, OUT_T >::update ( void const *const  input)
inlineoverrideprotectedvirtual

Internally update the filter output based on the given input.

This method behaves similarly to the public Filter::push method, but without copying the output to the client memory. This method is for internal workings of the filter framework.

Implements Filter.

Member Data Documentation

◆ end

template<typename IN_T , typename OUT_T >
int CachedFilter< IN_T, OUT_T >::end
private

The position in the internal buffer that points to the end of the cache.

New data will be written at this position and this value will be incremented, wrapping around at the boundary of the internal buffer. When the cache is full, this position points at the oldest data which will be overwritten by the next incoming data.


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