File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ #ifndef SENSESP_SRC_TRANSFORMS_FILTER_H_
2
+ #define SENSESP_SRC_TRANSFORMS_FILTER_H_
3
+
4
+ #include < functional>
5
+
6
+ namespace sensesp {
7
+
8
+ /* *
9
+ * @brief Transform that only emits the output if the filter condition returns
10
+ * true.
11
+ *
12
+ */
13
+ template <typename T>
14
+ class Filter : public Transform <T, T> {
15
+ public:
16
+ Filter (std::function<bool (const T&)> filter, String config_path = " " )
17
+ : Transform<T, T>(config_path), filter_{filter} {
18
+ this ->load_configuration ();
19
+ }
20
+ virtual void set (const T& new_value) override {
21
+ if (filter_ (new_value)) {
22
+ this ->emit (new_value);
23
+ }
24
+ }
25
+
26
+ private:
27
+ std::function<bool (const T&)> filter_;
28
+
29
+ };
30
+
31
+
32
+ } // namespace sensesp
33
+
34
+ #endif // SENSESP_SRC_TRANSFORMS_FILTER_H_
You can’t perform that action at this time.
0 commit comments