Modulo 5.0.0
Loading...
Searching...
No Matches
Predicate.hpp
1#pragma once
2
3#include <functional>
4#include <map>
5#include <optional>
6#include <string>
7
8namespace modulo_core {
9
13class Predicate {
14public:
15 explicit Predicate(const std::function<bool(void)>& predicate_function) : predicate_(std::move(predicate_function)) {}
16
17 bool get_value() const { return predicate_(); }
18
19 void set_predicate(const std::function<bool(void)>& predicate_function) { predicate_ = predicate_function; }
20
21 std::optional<bool> query() {
22 if (const auto new_value = predicate_(); !previous_value_ || new_value != *previous_value_) {
23 previous_value_ = new_value;
24 return new_value;
25 }
26 return {};
27 }
28
29private:
30 std::function<bool(void)> predicate_;
31 std::optional<bool> previous_value_;
32};
33
34}// namespace modulo_core
Modulo Core.