Modulo 4.2.2
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 previous_value_ = !predicate_();
17 }
18
19 bool get_value() const { return predicate_(); }
20
21 void set_predicate(const std::function<bool(void)>& predicate_function) { predicate_ = predicate_function; }
22
23 std::optional<bool> query() {
24 if (const auto new_value = predicate_(); new_value != previous_value_) {
25 previous_value_ = new_value;
26 return new_value;
27 }
28 return {};
29 }
30
31private:
32 std::function<bool(void)> predicate_;
33 bool previous_value_;
34};
35
36}// namespace modulo_core
Modulo Core.