Control Libraries 6.3.4
Loading...
Searching...
No Matches
State.cpp
1#include "state_representation/State.hpp"
2#include "state_representation/exceptions/NotImplementedException.hpp"
3
4namespace state_representation {
5State::State() : type_(StateType::STATE), name_(""), empty_(true) {}
6
7State::State(const StateType& type) : type_(type), name_(""), empty_(true) {}
8
9State::State(const StateType& type, const std::string& name, const bool& empty) :
10 type_(type), name_(name), empty_(empty), timestamp_(std::chrono::steady_clock::now()) {}
11
12State::State(const State& state) :
13 std::enable_shared_from_this<State>(state),
14 type_(state.type_),
15 name_(state.name_),
16 empty_(state.empty_),
17 timestamp_(std::chrono::steady_clock::now()) {}
18
19const StateType& State::get_type() const {
20 return this->type_;
21}
22
23bool State::is_empty() const {
24 return this->empty_;
25}
26
27void State::set_empty(bool empty) {
28 this->empty_ = empty;
29}
30
32 this->empty_ = false;
33 this->reset_timestamp();
34}
35
36const std::chrono::time_point<std::chrono::steady_clock>& State::get_timestamp() const {
37 return this->timestamp_;
38}
39
40void State::set_timestamp(const std::chrono::time_point<std::chrono::steady_clock>& timepoint) {
41 this->timestamp_ = timepoint;
42}
43
45 this->timestamp_ = std::chrono::steady_clock::now();
46}
47
48const std::string& State::get_name() const {
49 return this->name_;
50}
51
52void State::set_name(const std::string& name) {
53 this->name_ = name;
54}
55
56bool State::is_compatible(const State& state) const {
57 bool compatible = (this->name_ == state.name_);
58 return compatible;
59}
60
62 this->empty_ = true;
63}
64
65void State::set_data(const Eigen::VectorXd&) {
66 throw exceptions::NotImplementedException("set_data() is not implemented for the base State class");
67}
68
69void State::set_data(const std::vector<double>&) {
70 throw exceptions::NotImplementedException("set_data() is not implemented for the base State class");
71}
72
73void State::set_data(const Eigen::MatrixXd&) {
74 throw exceptions::NotImplementedException("set_data() is not implemented for the base State class");
75}
76
77std::ostream& operator<<(std::ostream& os, const State& state) {
78 if (state.is_empty()) {
79 os << "Empty ";
80 }
81 os << " State: " << state.get_name();
82 return os;
83}
84
85State::operator bool() const noexcept {
86 return !this->empty_;
87}
88
89void State::set_type(const StateType& type) {
90 this->type_ = type;
91}
92
93}// namespace state_representation
Abstract class to represent a state.
Definition: State.hpp:25
void reset_timestamp()
Reset the timestamp attribute to now.
Definition: State.cpp:44
virtual void initialize()
Initialize the State to a zero value.
Definition: State.cpp:61
const std::string & get_name() const
Getter of the name as const reference.
Definition: State.cpp:48
virtual void set_name(const std::string &name)
Setter of the name.
Definition: State.cpp:52
void set_timestamp(const std::chrono::time_point< std::chrono::steady_clock > &timepoint)
Setter of the timestamp attribute.
Definition: State.cpp:40
State()
Empty constructor.
Definition: State.cpp:5
const StateType & get_type() const
Getter of the type attribute.
Definition: State.cpp:19
void set_filled()
Setter of the empty attribute to false and also reset the timestamp.
Definition: State.cpp:31
void set_type(const StateType &type)
Override the state type.
Definition: State.cpp:89
virtual bool is_compatible(const State &state) const
Check if the state is compatible for operations with the state given as argument.
Definition: State.cpp:56
const std::chrono::time_point< std::chrono::steady_clock > & get_timestamp() const
Getter of the timestamp attribute.
Definition: State.cpp:36
virtual void set_data(const Eigen::VectorXd &data)
Set the data of the state from a single Eigen vector.
Definition: State.cpp:65
bool is_empty() const
Getter of the empty attribute.
Definition: State.cpp:23
void set_empty(bool empty=true)
Setter of the empty attribute.
Definition: State.cpp:27
Core state variables and objects.
std::ostream & operator<<(std::ostream &os, const Ellipsoid &ellipsoid)
Definition: Ellipsoid.cpp:185
StateType
The class types inheriting from State.
Definition: StateType.hpp:13