From 4cf24e1356f39a811cd5e7d51dbe66ccdf7bca6b Mon Sep 17 00:00:00 2001 From: Rohan Agrawal Date: Thu, 28 Jul 2016 17:12:31 -0700 Subject: [PATCH] added ros1 style get_param for non-variant types --- rclcpp/include/rclcpp/node.hpp | 3 +++ rclcpp/include/rclcpp/node_impl.hpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/rclcpp/include/rclcpp/node.hpp b/rclcpp/include/rclcpp/node.hpp index c80fe1cf78..7a1fcb1ea2 100644 --- a/rclcpp/include/rclcpp/node.hpp +++ b/rclcpp/include/rclcpp/node.hpp @@ -262,6 +262,9 @@ class Node : public std::enable_shared_from_this const std::string & name, rclcpp::parameter::ParameterVariant & parameter) const; + template + bool get_parameter(const std::string & name, ParameterT & parameter) const; + RCLCPP_PUBLIC std::vector describe_parameters(const std::vector & names) const; diff --git a/rclcpp/include/rclcpp/node_impl.hpp b/rclcpp/include/rclcpp/node_impl.hpp index 7c018ad31e..f7319ec602 100644 --- a/rclcpp/include/rclcpp/node_impl.hpp +++ b/rclcpp/include/rclcpp/node_impl.hpp @@ -368,6 +368,19 @@ void Node::register_param_change_callback(CallbackT && callback) this->parameters_callback_ = callback; } +template +bool Node::get_parameter(const std::string & name, ParameterT & parameter) const +{ + std::lock_guard lock(mutex_); + + if (parameters_.count(name)) { + parameter = parameters_.at(name).get_value(); + return true; + } else { + return false; + } +} + } // namespace node } // namespace rclcpp