Control Libraries 6.3.4
Loading...
Searching...
No Matches
Parameter.hpp
1#pragma once
2
3#include <memory>
4
5#include "state_representation/parameters/ParameterInterface.hpp"
6#include "state_representation/geometry/Ellipsoid.hpp"
7#include "state_representation/space/cartesian/CartesianPose.hpp"
8#include "state_representation/space/joint/JointPositions.hpp"
9
10namespace state_representation {
11
12template<typename T>
14private:
15 T value_;
16
17public:
22 explicit Parameter(const std::string& name);
23
29 explicit Parameter(const std::string& name, const T& value);
30
34 virtual ~Parameter() = default;
35
40 template<typename U>
41 Parameter(const Parameter<U>& parameter);
42
46 template<typename U>
48
54 template<typename U>
55 U get_value() const;
56
61 const T& get_value() const;
62
68
73 virtual void set_value(const T& value);
74
81 template<typename U>
82 friend std::ostream& operator<<(std::ostream& os, const Parameter<U>& parameter);
83};
84
85template<typename T>
86template<typename U>
88 Parameter<T>(parameter.get_name(), static_cast<T>(parameter.get_value())) {}
89
90template<typename T>
91template<typename U>
93 Parameter<T> temp(parameter);
94 *this = temp;
95 return *this;
96}
97
98template<typename T>
99template<typename U>
101 return static_cast<U>(this->value_);
102}
103
104template<typename T>
105inline const T& Parameter<T>::get_value() const {
106 return this->value_;
107}
108
109template<typename T>
111 return this->value_;
112}
113
114template<typename T>
115inline void Parameter<T>::set_value(const T& value) {
116 this->set_filled();
117 this->value_ = value;
118}
119
120template<typename T>
121static std::shared_ptr<Parameter<T>> make_shared_parameter(const std::string& name, const T& param_value) {
122 return std::make_shared<Parameter<T>>(name, param_value);
123}
124
125[[maybe_unused]] static std::shared_ptr<ParameterInterface> make_shared_parameter_interface(
126 const std::string& name, const ParameterType& type, const StateType& parameter_state_type = StateType::NONE
127) {
128 switch (type) {
129 case ParameterType::BOOL:
130 return std::make_shared<Parameter<bool>>(name);
131 case ParameterType::BOOL_ARRAY:
132 return std::make_shared<Parameter<std::vector<bool>>>(name);
133 case ParameterType::INT:
134 return std::make_shared<Parameter<int>>(name);
135 case ParameterType::INT_ARRAY:
136 return std::make_shared<Parameter<std::vector<int>>>(name);
137 case ParameterType::DOUBLE:
138 return std::make_shared<Parameter<double>>(name);
139 case ParameterType::DOUBLE_ARRAY:
140 return std::make_shared<Parameter<std::vector<double>>>(name);
141 case ParameterType::STRING:
142 return std::make_shared<Parameter<std::string>>(name);
143 case ParameterType::STRING_ARRAY:
144 return std::make_shared<Parameter<std::vector<std::string>>>(name);
145 case ParameterType::STATE: {
146 switch (parameter_state_type) {
147 case StateType::CARTESIAN_STATE:
148 return std::make_shared<Parameter<CartesianState>>(name);
149 case StateType::CARTESIAN_POSE:
150 return std::make_shared<Parameter<CartesianPose>>(name);
151 case StateType::JOINT_STATE:
152 return std::make_shared<Parameter<JointState>>(name);
153 case StateType::JOINT_POSITIONS:
154 return std::make_shared<Parameter<JointPositions>>(name);
155 case StateType::GEOMETRY_ELLIPSOID:
156 return std::make_shared<Parameter<Ellipsoid>>(name);
157 case StateType::NONE:
158 throw exceptions::InvalidParameterException("No StateType provided.");
159 default:
160 throw exceptions::InvalidParameterException("This StateType is not supported for parameters.");
161 }
162 }
163 case ParameterType::VECTOR:
164 return std::make_shared<Parameter<Eigen::VectorXd>>(name);
165 case ParameterType::MATRIX:
166 return std::make_shared<Parameter<Eigen::MatrixXd>>(name);
167 default:
168 throw exceptions::InvalidParameterException("This StateType is not supported for parameters.");
169 }
170}
171}// namespace state_representation
friend std::ostream & operator<<(std::ostream &os, const Parameter< U > &parameter)
Overload the ostream operator for printing.
Parameter(const std::string &name, const T &value)
Constructor with a name and a value.
virtual ~Parameter()=default
Default virtual destructor.
U get_value() const
Getter of the value attribute.
Definition: Parameter.hpp:100
const T & get_value() const
Getter of the value attribute.
Definition: Parameter.hpp:105
Parameter(const Parameter< U > &parameter)
Copy constructor.
Definition: Parameter.hpp:87
Parameter< T > & operator=(const Parameter< U > &parameter)
Conversion equality.
Definition: Parameter.hpp:92
Parameter(const std::string &name)
Constructor with name of the parameter.
virtual void set_value(const T &value)
Setter of the value attribute.
Definition: Parameter.hpp:115
T & get_value()
Getter of the value attribute.
Definition: Parameter.hpp:110
Core state variables and objects.
ParameterType
The parameter value types.
StateType
The class types inheriting from State.
Definition: StateType.hpp:13