ROS 2 rclcpp + rcl - lyrical  lyrical
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/node.hpp"
28 #include "rclcpp/parameter_value.hpp"
29 #include "rclcpp/node_interfaces/get_node_parameters_interface.hpp"
30 #include "rclcpp/visibility_control.hpp"
31 #include "node_interfaces/node_parameters_interface.hpp"
32 
33 namespace rclcpp
34 {
35 
36 // Implements ParameterDesription class with builder design pattern
38 {
39 public:
40  RCLCPP_SMART_PTR_DEFINITIONS(ParameterDescription)
41 
42  // List of classes the builder manages
43  RCLCPP_PUBLIC
45 
46  // Our Main build methods which will construct the base class
47  RCLCPP_PUBLIC rcl_interfaces::msg::ParameterDescriptor build() const;
48 
49  // Builder Methods:
50  // Describes the instances in a parameter_description object
51  RCLCPP_PUBLIC ParameterDescription & set_name(const std::string & name);
52  RCLCPP_PUBLIC ParameterDescription & set_type(std::uint8_t type);
53  RCLCPP_PUBLIC ParameterDescription & set_description_text(const std::string & description);
54  RCLCPP_PUBLIC ParameterDescription & set_additional_constraints(const std::string & constraints);
55  RCLCPP_PUBLIC ParameterDescription & set_read_only(bool read_only);
56  RCLCPP_PUBLIC ParameterDescription & set_dynamic_typing(bool dynamic_typing);
57  RCLCPP_PUBLIC ParameterDescription & set_floating_point_description_range(
58  float min, float max, float step);
59  RCLCPP_PUBLIC ParameterDescription & set_integer_description_range(int min, int max, int step);
60 
61  // Need the current node in order to begin the configuration state
62  // for it via the declare_parameter function
63  template<typename NodeT>
64  ParameterDescription & declare_parameter(
65  const rclcpp::ParameterValue & default_value,
66  NodeT && node)
67  {
68  auto node_param = rclcpp::node_interfaces::get_node_parameters_interface(node);
69  node_param->declare_parameter(
70  parameter_descriptor.name, default_value,
71  parameter_descriptor);
72  return *this;
73  }
74 
75 private:
76  // The main descriptor object we're meant to initialize and adjust
77  rcl_interfaces::msg::ParameterDescriptor parameter_descriptor;
78 };
79 
80 } // namespace rclcpp
81 
82 #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.