Control Libraries 6.3.4
Loading...
Searching...
No Matches
Event.hpp
1#pragma once
2
3#include "state_representation/parameters/Predicate.hpp"
4
5namespace state_representation {
6
14class Event : public Predicate {
15private:
16 bool previous_predicate_value_;
17
18public:
22 explicit Event(const std::string& name);
23
28 bool read_value();
29
34 void set_value(const bool& value) override;
35
40 bool get_previous_value() const;
41
48 friend std::ostream& operator<<(std::ostream& os, const Event& event);
49};
50
51inline bool Event::read_value() {
52 bool value = this->get_value();
53 this->Predicate::set_value(false);
54 return value;
55}
56
57inline void Event::set_value(const bool& value) {
58 bool current_value = this->get_value();
59 bool result = value && (current_value || !this->previous_predicate_value_);
60 this->previous_predicate_value_ = value;
61 this->Predicate::set_value(result);
62}
63
64inline bool Event::get_previous_value() const {
65 return this->previous_predicate_value_;
66}
67}// namespace state_representation
An event is a predicate with memory. Its purpose is to be true only once and change value only when t...
Definition: Event.hpp:14
void set_value(const bool &value) override
Setter of the value attribute.
Definition: Event.hpp:57
friend std::ostream & operator<<(std::ostream &os, const Event &event)
Overload the ostream operator for printing.
Definition: Event.cpp:7
bool read_value()
Read the value of the event, modifying its value as it has been accessed once.
Definition: Event.hpp:51
bool get_previous_value() const
Getter of the previous value. Does not affect the behavior of the event (as opposed to read_value).
Definition: Event.hpp:64
U get_value() const
Getter of the value attribute.
Definition: Parameter.hpp:100
virtual void set_value(const bool &value)
Setter of the value attribute.
Definition: Parameter.hpp:115
A predicate is a boolean parameter as in the logic formalism.
Definition: Predicate.hpp:11
Core state variables and objects.