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> {
44 explicit State(
const StateType& type,
const std::string& name,
const bool& empty =
true);
95 const std::chrono::time_point<std::chrono::steady_clock>&
get_timestamp()
const;
101 void set_timestamp(
const std::chrono::time_point<std::chrono::steady_clock>& timepoint);
111 const std::string&
get_name()
const;
116 virtual void set_name(
const std::string& name);
122 template<
typename DurationT>
123 bool is_deprecated(
const std::chrono::duration<int64_t, DurationT>& time_delay);
140 virtual void set_data(
const Eigen::VectorXd& data);
146 virtual void set_data(
const std::vector<double>& data);
152 virtual void set_data(
const Eigen::MatrixXd& data);
166 explicit operator bool() const noexcept;
179 std::chrono::time_point<std::chrono::steady_clock> timestamp_;
183 std::swap(state1.type_, state2.type_);
184 std::swap(state1.name_, state2.name_);
185 std::swap(state1.empty_, state2.empty_);
186 std::swap(state1.timestamp_, state2.timestamp_);
195template<
typename DurationT>
197 return ((std::chrono::steady_clock::now() - this->timestamp_) > time_delay);
201std::shared_ptr<State> make_shared_state(
const T& state) {
202 return std::make_shared<T>(state);
Abstract class to represent a state.
void reset_timestamp()
Reset the timestamp attribute to now.
bool is_deprecated(const std::chrono::duration< int64_t, DurationT > &time_delay)
Check if the state is deprecated given a certain time delay.
virtual void initialize()
Initialize the State to a zero value.
const std::string & get_name() const
Getter of the name as const reference.
virtual void set_name(const std::string &name)
Setter of the name.
void set_timestamp(const std::chrono::time_point< std::chrono::steady_clock > &timepoint)
Setter of the timestamp attribute.
State()
Empty constructor.
const StateType & get_type() const
Getter of the type attribute.
void set_filled()
Setter of the empty attribute to false and also reset the timestamp.
void set_type(const StateType &type)
Override the state type.
virtual bool is_compatible(const State &state) const
Check if the state is compatible for operations with the state given as argument.
friend std::ostream & operator<<(std::ostream &os, const State &state)
Overload the ostream operator for printing.
const std::chrono::time_point< std::chrono::steady_clock > & get_timestamp() const
Getter of the timestamp attribute.
State & operator=(const State &state)
Copy assignment operator that have to be defined to the custom assignment operator.
virtual ~State()=default
Virtual destructor.
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 a single 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.