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/visibility_control.hpp"
32 enum ParameterType : uint8_t
34 PARAMETER_NOT_SET = rcl_interfaces::msg::ParameterType::PARAMETER_NOT_SET,
35 PARAMETER_BOOL = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL,
36 PARAMETER_INTEGER = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER,
37 PARAMETER_DOUBLE = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE,
38 PARAMETER_STRING = rcl_interfaces::msg::ParameterType::PARAMETER_STRING,
39 PARAMETER_BYTE_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY,
40 PARAMETER_BOOL_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL_ARRAY,
41 PARAMETER_INTEGER_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER_ARRAY,
42 PARAMETER_DOUBLE_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE_ARRAY,
43 PARAMETER_STRING_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY,
53 operator<<(std::ostream & os, ParameterType type);
66 : std::runtime_error(
"expected [" +
to_string(expected) +
"] got [" +
to_string(actual) +
"]")
79 explicit ParameterValue(
const rcl_interfaces::msg::ParameterValue & value);
103 explicit ParameterValue(
const std::vector<uint8_t> & byte_array_value);
106 explicit ParameterValue(
const std::vector<bool> & bool_array_value);
109 explicit ParameterValue(
const std::vector<int> & int_array_value);
112 explicit ParameterValue(
const std::vector<int64_t> & int_array_value);
115 explicit ParameterValue(
const std::vector<float> & double_array_value);
118 explicit ParameterValue(
const std::vector<double> & double_array_value);
121 explicit ParameterValue(
const std::vector<std::string> & string_array_value);
130 rcl_interfaces::msg::ParameterValue
145 template<ParameterType type>
147 typename std::enable_if<type == ParameterType::PARAMETER_BOOL, const bool &>::type
150 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BOOL) {
153 return value_.bool_value;
156 template<ParameterType type>
158 typename std::enable_if<type == ParameterType::PARAMETER_INTEGER, const int64_t &>::type
161 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER) {
164 return value_.integer_value;
167 template<ParameterType type>
169 typename std::enable_if<type == ParameterType::PARAMETER_DOUBLE, const double &>::type
172 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE) {
175 return value_.double_value;
178 template<ParameterType type>
180 typename std::enable_if<type == ParameterType::PARAMETER_STRING, const std::string &>::type
183 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_STRING) {
186 return value_.string_value;
189 template<ParameterType type>
191 typename std::enable_if<
192 type == ParameterType::PARAMETER_BYTE_ARRAY,
const std::vector<uint8_t> &>::type
195 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BYTE_ARRAY) {
198 return value_.byte_array_value;
201 template<ParameterType type>
203 typename std::enable_if<
204 type == ParameterType::PARAMETER_BOOL_ARRAY,
const std::vector<bool> &>::type
207 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_BOOL_ARRAY) {
210 return value_.bool_array_value;
213 template<ParameterType type>
215 typename std::enable_if<
216 type == ParameterType::PARAMETER_INTEGER_ARRAY,
const std::vector<int64_t> &>::type
219 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_INTEGER_ARRAY) {
222 return value_.integer_array_value;
225 template<ParameterType type>
227 typename std::enable_if<
228 type == ParameterType::PARAMETER_DOUBLE_ARRAY,
const std::vector<double> &>::type
231 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_DOUBLE_ARRAY) {
234 return value_.double_array_value;
237 template<ParameterType type>
239 typename std::enable_if<
240 type == ParameterType::PARAMETER_STRING_ARRAY,
const std::vector<std::string> &>::type
243 if (value_.type != rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY) {
246 return value_.string_array_value;
251 template<
typename type>
253 typename std::enable_if<std::is_same<type, bool>::value,
const bool &>::type
256 return get<ParameterType::PARAMETER_BOOL>();
259 template<
typename type>
261 typename std::enable_if<
262 std::is_integral<type>::value && !std::is_same<type, bool>::value,
const int64_t &>::type
265 return get<ParameterType::PARAMETER_INTEGER>();
268 template<
typename type>
270 typename std::enable_if<std::is_floating_point<type>::value,
const double &>::type
273 return get<ParameterType::PARAMETER_DOUBLE>();
276 template<
typename type>
278 typename std::enable_if<std::is_convertible<type, std::string>::value,
const std::string &>::type
281 return get<ParameterType::PARAMETER_STRING>();
284 template<
typename type>
286 typename std::enable_if<
288 type,
const std::vector<uint8_t> &>::value,
const std::vector<uint8_t> &>::type
291 return get<ParameterType::PARAMETER_BYTE_ARRAY>();
294 template<
typename type>
296 typename std::enable_if<
298 type,
const std::vector<bool> &>::value,
const std::vector<bool> &>::type
301 return get<ParameterType::PARAMETER_BOOL_ARRAY>();
304 template<
typename type>
306 typename std::enable_if<
308 type,
const std::vector<int> &>::value,
const std::vector<int64_t> &>::type
311 return get<ParameterType::PARAMETER_INTEGER_ARRAY>();
314 template<
typename type>
316 typename std::enable_if<
318 type,
const std::vector<int64_t> &>::value,
const std::vector<int64_t> &>::type
321 return get<ParameterType::PARAMETER_INTEGER_ARRAY>();
324 template<
typename type>
326 typename std::enable_if<
328 type,
const std::vector<float> &>::value,
const std::vector<double> &>::type
331 return get<ParameterType::PARAMETER_DOUBLE_ARRAY>();
334 template<
typename type>
336 typename std::enable_if<
338 type,
const std::vector<double> &>::value,
const std::vector<double> &>::type
341 return get<ParameterType::PARAMETER_DOUBLE_ARRAY>();
344 template<
typename type>
346 typename std::enable_if<
348 type,
const std::vector<std::string> &>::value,
const std::vector<std::string> &>::type
351 return get<ParameterType::PARAMETER_STRING_ARRAY>();
355 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.