Control Libraries 6.3.4
Loading...
Searching...
No Matches
SpatialState.hpp
1#pragma once
2
3#include "state_representation/State.hpp"
4
5namespace state_representation {
6class SpatialState : public State {
7private:
8 std::string reference_frame_;
9
10public:
15
20 explicit SpatialState(const StateType& type);
21
29 explicit SpatialState(
30 const StateType& type, const std::string& name, const std::string& reference_frame = "world",
31 const bool& empty = true
32 );
33
37 SpatialState(const SpatialState& state) = default;
38
44 friend void swap(SpatialState& state1, SpatialState& state2);
45
51 SpatialState& operator=(const SpatialState& state);
52
57 const std::string& get_reference_frame() const;
58
63 virtual void set_reference_frame(const std::string& reference_frame);
64
69 virtual bool is_compatible(const State& state) const override;
70
77 friend std::ostream& operator<<(std::ostream& os, const SpatialState& state);
78};
79
80inline void swap(SpatialState& state1, SpatialState& state2) {
81 swap(static_cast<State&>(state1), static_cast<State&>(state2));
82 std::swap(state1.reference_frame_, state2.reference_frame_);
83}
84
86 SpatialState tmp(state);
87 swap(*this, tmp);
88 return *this;
89}
90
91inline const std::string& SpatialState::get_reference_frame() const {
92 return this->reference_frame_;
93}
94
95inline void SpatialState::set_reference_frame(const std::string& reference_frame) {
96 this->reference_frame_ = reference_frame;
97}
98
99inline bool SpatialState::is_compatible(const State& state) const {
100 bool compatible = (this->get_name() == state.get_name())
101 && (this->reference_frame_ == dynamic_cast<const SpatialState&>(state).reference_frame_);
102 return compatible;
103}
104}
SpatialState(const SpatialState &state)=default
Copy constructor from another SpatialState.
virtual void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
virtual bool is_compatible(const State &state) const override
Check if the state is compatible for operations with the state given as argument.
SpatialState & operator=(const SpatialState &state)
Copy assignment operator that have to be defined to the custom assignment operator.
friend std::ostream & operator<<(std::ostream &os, const SpatialState &state)
Overload the ostream operator for printing.
const std::string & get_reference_frame() const
Getter of the reference frame as const reference.
SpatialState()
Empty constructor.
Definition: SpatialState.cpp:5
friend void swap(SpatialState &state1, SpatialState &state2)
Swap the values of the two SpatialState.
Abstract class to represent a state.
Definition: State.hpp:25
const std::string & get_name() const
Getter of the name as const reference.
Definition: State.cpp:48
Core state variables and objects.
void swap(CartesianState &state1, CartesianState &state2)
StateType
The class types inheriting from State.
Definition: StateType.hpp:13