Skip to content

Commit

Permalink
Merge pull request #715 from SignalK/filter_transform
Browse files Browse the repository at this point in the history
Implement a filter transform
  • Loading branch information
mairas authored Aug 2, 2024
2 parents ef03b90 + e97a6fe commit a2d7611
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/sensesp/transforms/filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef SENSESP_SRC_TRANSFORMS_FILTER_H_
#define SENSESP_SRC_TRANSFORMS_FILTER_H_

#include <functional>

namespace sensesp {

/**
* @brief Transform that only emits the output if the filter condition returns
* true.
*
*/
template <typename T>
class Filter : public Transform<T, T> {
public:
Filter(std::function<bool(const T&)> filter, String config_path = "")
: Transform<T, T>(config_path), filter_{filter} {
this->load_configuration();
}
virtual void set(const T& new_value) override {
if (filter_(new_value)) {
this->emit(new_value);
}
}

private:
std::function<bool(const T&)> filter_;

};


} // namespace sensesp

#endif // SENSESP_SRC_TRANSFORMS_FILTER_H_

0 comments on commit a2d7611

Please sign in to comment.