ROS 2 rclcpp + rcl - rolling  rolling-20536064
ROS 2 C++ Client Library with ROS Client Library
parameter_descriptor_wrapper.hpp
1 // Copyright 2023 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_
16 #define RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_
17 
18 // C++ Standard library includes
19 #include <functional>
20 #include <utility>
21 #include <memory>
22 #include <string>
23 
24 // Additional ROS libraries needed
25 #include "rcl_interfaces/msg/parameter_descriptor.hpp"
26 
27 #include "rclcpp/parameter_value.hpp"
28 #include "rclcpp/node_interfaces/get_node_parameters_interface.hpp"
29 #include "rclcpp/visibility_control.hpp"
30 #include "node_interfaces/node_parameters_interface.hpp"
31 
32 namespace rclcpp
33 {
34 
35 // Implements ParameterDesription class with builder design pattern
37 {
38 public:
39  RCLCPP_SMART_PTR_DEFINITIONS(ParameterDescription)
40 
41  // List of classes the builder manages
42  RCLCPP_PUBLIC
44 
45  // Our Main build methods which will construct the base class
46  RCLCPP_PUBLIC rcl_interfaces::msg::ParameterDescriptor build() const;
47 
48  // Builder Methods:
49  // Describes the instances in a parameter_description object
50  RCLCPP_PUBLIC ParameterDescription & set_name(const std::string & name);
51  RCLCPP_PUBLIC ParameterDescription & set_type(std::uint8_t type);
52  RCLCPP_PUBLIC ParameterDescription & set_description_text(const std::string & description);
53  RCLCPP_PUBLIC ParameterDescription & set_additional_constraints(const std::string & constraints);
54  RCLCPP_PUBLIC ParameterDescription & set_read_only(bool read_only);
55  RCLCPP_PUBLIC ParameterDescription & set_dynamic_typing(bool dynamic_typing);
56  RCLCPP_PUBLIC ParameterDescription & set_floating_point_description_range(
57  float min, float max, float step);
58  RCLCPP_PUBLIC ParameterDescription & set_integer_description_range(int min, int max, int step);
59 
60  // Need the current node in order to begin the configuration state
61  // for it via the declare_parameter function
62  template<typename NodeT>
63  ParameterDescription & declare_parameter(
64  const rclcpp::ParameterValue & default_value,
65  NodeT && node)
66  {
67  auto node_param = rclcpp::node_interfaces::get_node_parameters_interface(node);
68  node_param->declare_parameter(
69  parameter_descriptor.name, default_value,
70  parameter_descriptor);
71  return *this;
72  }
73 
74 private:
75  // The main descriptor object we're meant to initialize and adjust
76  rcl_interfaces::msg::ParameterDescriptor parameter_descriptor;
77 };
78 
79 } // namespace rclcpp
80 
81 #endif // RCLCPP__PARAMETER_DESCRIPTOR_WRAPPER_HPP_
Store the type and value of a parameter.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.