SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
filter.h
Go to the documentation of this file.
1#ifndef SENSESP_SRC_TRANSFORMS_FILTER_H_
2#define SENSESP_SRC_TRANSFORMS_FILTER_H_
3
4#include <functional>
5
7
8namespace sensesp {
9
15template <typename T>
16class Filter : public Transform<T, T> {
17 public:
18 Filter(std::function<bool(const T&)> filter, String config_path = "")
19 : Transform<T, T>(config_path), filter_{filter} {
20 this->load();
21 }
22 virtual void set(const T& new_value) override {
23 if (filter_(new_value)) {
24 this->emit(new_value);
25 }
26 }
27
28 private:
29 std::function<bool(const T&)> filter_;
30};
31
32} // namespace sensesp
33
34#endif // SENSESP_SRC_TRANSFORMS_FILTER_H_
virtual bool load() override
Load and populate the object from a persistent storage.
Definition saveable.cpp:8
Transform that only emits the output if the filter condition returns true.
Definition filter.h:16
Filter(std::function< bool(const T &)> filter, String config_path="")
Definition filter.h:18
virtual void set(const T &new_value) override
Definition filter.h:22
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:53
void emit(const T &new_value)