15 #ifndef RCLCPP__PARAMETER_VALUE_HPP_
16 #define RCLCPP__PARAMETER_VALUE_HPP_
25 #include "rcl_interfaces/msg/parameter_type.hpp"
26 #include "rcl_interfaces/msg/parameter_value.hpp"
27 #include "rclcpp/exceptions/exceptions.hpp"
28 #include "rclcpp/visibility_control.hpp"
33 enum ParameterType : uint8_t
35 PARAMETER_NOT_SET = rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET,
36 PARAMETER_BOOL = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL,
37 PARAMETER_INTEGER = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER,
38 PARAMETER_DOUBLE = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE,
39 PARAMETER_STRING = rcl_interfaces::msg::ParameterType::PARAMETER_STRING,
40 PARAMETER_BYTE_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY,
41 PARAMETER_BOOL_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL_ARRAY,
42 PARAMETER_INTEGER_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER_ARRAY,
43 PARAMETER_DOUBLE_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE_ARRAY,
44 PARAMETER_STRING_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY,
54 operator<<(std::ostream & os, ParameterType type);
67 : std::runtime_error(
"expected [" +
to_string(expected) +
"] got [" +
to_string(actual) +
"]")
80 explicit ParameterValue(
const rcl_interfaces::msg::ParameterValue & value);
104 explicit ParameterValue(
const std::vector<uint8_t> & byte_array_value);
107 explicit ParameterValue(
const std::vector<bool> & bool_array_value);
110 explicit ParameterValue(
const std::vector<int> & int_array_value);
113 explicit ParameterValue(
const std::vector<int64_t> & int_array_value);
116 explicit ParameterValue(
const std::vector<float> & double_array_value);
119 explicit ParameterValue(
const std::vector<double> & double_array_value);
122 explicit ParameterValue(
const std::vector<std::string> & string_array_value);
131 rcl_interfaces::msg::ParameterValue
146 template<ParameterType type>
148 typename std::enable_if<type == ParameterType::PARAMETER_BOOL, const bool &>::type
151 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BOOL) {
154 return value_.bool_value;
157 template<ParameterType type>
159 typename std::enable_if<type == ParameterType::PARAMETER_INTEGER, const int64_t &>::type
162 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER) {
165 return value_.integer_value;
168 template<ParameterType type>
170 typename std::enable_if<type == ParameterType::PARAMETER_DOUBLE, const double &>::type
173 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE) {
176 return value_.double_value;
179 template<ParameterType type>
181 typename std::enable_if<type == ParameterType::PARAMETER_STRING, const std::string &>::type
184 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_STRING) {
187 return value_.string_value;
190 template<ParameterType type>
192 typename std::enable_if<
193 type == ParameterType::PARAMETER_BYTE_ARRAY,
const std::vector<uint8_t> &>::type
196 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY) {
199 return value_.byte_array_value;
202 template<ParameterType type>
204 typename std::enable_if<
205 type == ParameterType::PARAMETER_BOOL_ARRAY,
const std::vector<bool> &>::type
208 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BOOL_ARRAY) {
211 return value_.bool_array_value;
214 template<ParameterType type>
216 typename std::enable_if<
217 type == ParameterType::PARAMETER_INTEGER_ARRAY,
const std::vector<int64_t> &>::type
220 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER_ARRAY) {
223 return value_.integer_array_value;
226 template<ParameterType type>
228 typename std::enable_if<
229 type == ParameterType::PARAMETER_DOUBLE_ARRAY,
const std::vector<double> &>::type
232 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE_ARRAY) {
235 return value_.double_array_value;
238 template<ParameterType type>
240 typename std::enable_if<
241 type == ParameterType::PARAMETER_STRING_ARRAY,
const std::vector<std::string> &>::type
244 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY) {
247 return value_.string_array_value;
252 template<
typename type>
254 typename std::enable_if<std::is_same<type, bool>::value,
const bool &>::type
257 return get<ParameterType::PARAMETER_BOOL>();
260 template<
typename type>
262 typename std::enable_if<
263 std::is_integral<type>::value && !std::is_same<type, bool>::value,
const int64_t &>::type
266 return get<ParameterType::PARAMETER_INTEGER>();
269 template<
typename type>
271 typename std::enable_if<std::is_floating_point<type>::value,
const double &>::type
274 return get<ParameterType::PARAMETER_DOUBLE>();
277 template<
typename type>
279 typename std::enable_if<std::is_convertible<type, std::string>::value,
const std::string &>::type
282 return get<ParameterType::PARAMETER_STRING>();
285 template<
typename type>
287 typename std::enable_if<
289 type,
const std::vector<uint8_t> &>::value,
const std::vector<uint8_t> &>::type
292 return get<ParameterType::PARAMETER_BYTE_ARRAY>();
295 template<
typename type>
297 typename std::enable_if<
299 type,
const std::vector<bool> &>::value,
const std::vector<bool> &>::type
302 return get<ParameterType::PARAMETER_BOOL_ARRAY>();
305 template<
typename type>
307 typename std::enable_if<
309 type,
const std::vector<int> &>::value,
const std::vector<int64_t> &>::type
312 return get<ParameterType::PARAMETER_INTEGER_ARRAY>();
315 template<
typename type>
317 typename std::enable_if<
319 type,
const std::vector<int64_t> &>::value,
const std::vector<int64_t> &>::type
322 return get<ParameterType::PARAMETER_INTEGER_ARRAY>();
325 template<
typename type>
327 typename std::enable_if<
329 type,
const std::vector<float> &>::value,
const std::vector<double> &>::type
332 return get<ParameterType::PARAMETER_DOUBLE_ARRAY>();
335 template<
typename type>
337 typename std::enable_if<
339 type,
const std::vector<double> &>::value,
const std::vector<double> &>::type
342 return get<ParameterType::PARAMETER_DOUBLE_ARRAY>();
345 template<
typename type>
347 typename std::enable_if<
349 type,
const std::vector<std::string> &>::value,
const std::vector<std::string> &>::type
352 return get<ParameterType::PARAMETER_STRING_ARRAY>();
356 rcl_interfaces::msg::ParameterValue value_;
Indicate the parameter type does not match the expected type.
RCLCPP_PUBLIC ParameterTypeException(ParameterType expected, ParameterType actual)
Construct an instance.
Store the type and value of a parameter.
RCLCPP_PUBLIC rcl_interfaces::msg::ParameterValue to_value_msg() const
Return a message populated with the parameter value.
RCLCPP_PUBLIC ParameterType get_type() const
Return an enum indicating the type of the set value.
RCLCPP_PUBLIC bool operator==(const ParameterValue &rhs) const
Equal operator.
RCLCPP_PUBLIC bool operator!=(const ParameterValue &rhs) const
Not equal operator.
RCLCPP_PUBLIC ParameterValue()
Construct a parameter value with type PARAMETER_NOT_SET.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC std::string to_string(const FutureReturnCode &future_return_code)
String conversion function for FutureReturnCode.
RCLCPP_PUBLIC std::ostream & operator<<(std::ostream &os, const FutureReturnCode &future_return_code)
Stream operator for FutureReturnCode.