9#include <eigen3/Eigen/Core>
10#include <eigen3/Eigen/Dense>
12#include "state_representation/StateType.hpp"
13#include "state_representation/MathTools.hpp"
25class State :
public std::enable_shared_from_this<State> {
36 explicit State(
const std::string& name);
80 const std::chrono::time_point<std::chrono::steady_clock>&
get_timestamp()
const;
85 virtual void set_name(
const std::string& name);
95 virtual void set_data(
const Eigen::VectorXd& data);
100 virtual void set_data(
const std::vector<double>& data);
105 virtual void set_data(
const Eigen::MatrixXd& data);
128 template<
typename DurationT>
129 bool is_deprecated(
const std::chrono::duration<int64_t, DurationT>& time_delay)
const;
134 virtual void reset();
140 explicit operator bool() const noexcept;
148 friend std::ostream& operator<<(std::ostream& os, const
State& state);
178 std::chrono::time_point<std::chrono::steady_clock> timestamp_;
182 std::swap(state1.name_, state2.name_);
183 std::swap(state1.empty_, state2.empty_);
184 std::swap(state1.timestamp_, state2.timestamp_);
187template<
typename DurationT>
189 return ((std::chrono::steady_clock::now() - this->timestamp_) > time_delay);
193std::shared_ptr<State> make_shared_state(
const T& state) {
194 return std::make_shared<T>(state);
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.
virtual ~State()=default
Virtual destructor.
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.
StateType
The class types inheriting from State.