1#include "state_representation/State.hpp"
2#include "state_representation/exceptions/EmptyStateException.hpp"
3#include "state_representation/exceptions/NotImplementedException.hpp"
10 type_(
StateType::STATE), name_(name), empty_(true), timestamp_(std::chrono::steady_clock::now()) {}
13 std::enable_shared_from_this<
State>(state),
17 timestamp_(state.timestamp_) {}
38 return this->timestamp_;
62 this->timestamp_ = std::chrono::steady_clock::now();
82 return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(
83 std::chrono::steady_clock::now() - this->timestamp_
88 return this->
get_age() >= time_delay;
95State::operator bool() const noexcept {
100 std::string prefix = this->
is_empty() ?
"Empty " :
"";
101 return prefix + get_state_type_name(this->type_) +
": '" + this->
get_name() +
"'";
105 os << state.to_string();
Abstract class to represent a state.
void reset_timestamp()
Reset the timestamp attribute to now.
const std::string & get_name() const
Getter of the name attribute.
virtual void set_name(const std::string &name)
Setter of the name attribute.
State()
Empty constructor.
const StateType & get_type() const
Getter of the type attribute.
void set_type(const StateType &type)
Setter of the state type attribute.
virtual std::string to_string() const
Convert the state to its string representation.
const std::chrono::time_point< std::chrono::steady_clock > & get_timestamp() const
Getter of the timestamp attribute.
virtual void reset()
Reset the object to a post-construction state.
virtual bool is_incompatible(const State &state) const
Check if the state is incompatible for operations with the state given as argument.
State & operator=(const State &state)
Copy assignment operator that has to be defined to the custom assignment operator.
void assert_not_empty() const
Throw an exception if the state is empty.
double get_age() const
Get the age of the state, i.e. the time since the last modification.
bool is_deprecated(double time_delay) const
Check if the state is deprecated given a certain time delay.
friend void swap(State &state1, State &state2)
Swap the values of the two states.
virtual void set_data(const Eigen::VectorXd &data)
Set the data of the state from an Eigen vector.
bool is_empty() const
Getter of the empty attribute.
void set_empty(bool empty=true)
Setter of the empty attribute.
Core state variables and objects.
std::ostream & operator<<(std::ostream &os, const AnalogIOState &state)
StateType
The class types inheriting from State.