From 4dbc7192d296c3f701c9182612d6b174ea5acb84 Mon Sep 17 00:00:00 2001 From: ivanpauno Date: Wed, 21 Aug 2019 09:17:25 -0300 Subject: [PATCH] Fix get_node_interfaces functions taking a pointer (#821) Signed-off-by: ivanpauno --- .../get_node_base_interface.hpp | 8 +++++--- .../get_node_timers_interface.hpp | 8 +++++--- .../get_node_topics_interface.hpp | 8 +++++--- .../test_get_node_interfaces.cpp | 20 +++++++++++++++++++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/rclcpp/include/rclcpp/node_interfaces/get_node_base_interface.hpp b/rclcpp/include/rclcpp/node_interfaces/get_node_base_interface.hpp index eee825ab7f..cfc5917689 100644 --- a/rclcpp/include/rclcpp/node_interfaces/get_node_base_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/get_node_base_interface.hpp @@ -123,16 +123,18 @@ template< typename std::enable_if::value, int>::type = 0 > rclcpp::node_interfaces::NodeBaseInterface * -get_node_base_interface(NodeType && node_pointer) +get_node_base_interface(NodeType node_pointer) { // Forward pointers to detail implmentation directly. - return detail::get_node_base_interface_from_pointer(std::forward(node_pointer)); + return detail::get_node_base_interface_from_pointer(node_pointer); } /// Get the NodeBaseInterface as a pointer from a "Node like" object. template< typename NodeType, - typename std::enable_if::value, int>::type = 0 + typename std::enable_if< + !std::is_pointer::type>::value, int + >::type = 0 > rclcpp::node_interfaces::NodeBaseInterface * get_node_base_interface(NodeType && node_reference) diff --git a/rclcpp/include/rclcpp/node_interfaces/get_node_timers_interface.hpp b/rclcpp/include/rclcpp/node_interfaces/get_node_timers_interface.hpp index 54282a8a84..9c54f06e9c 100644 --- a/rclcpp/include/rclcpp/node_interfaces/get_node_timers_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/get_node_timers_interface.hpp @@ -123,16 +123,18 @@ template< typename std::enable_if::value, int>::type = 0 > rclcpp::node_interfaces::NodeTimersInterface * -get_node_timers_interface(NodeType && node_pointer) +get_node_timers_interface(NodeType node_pointer) { // Forward pointers to detail implmentation directly. - return detail::get_node_timers_interface_from_pointer(std::forward(node_pointer)); + return detail::get_node_timers_interface_from_pointer(node_pointer); } /// Get the NodeTimersInterface as a pointer from a "Node like" object. template< typename NodeType, - typename std::enable_if::value, int>::type = 0 + typename std::enable_if< + !std::is_pointer::type>::value, int + >::type = 0 > rclcpp::node_interfaces::NodeTimersInterface * get_node_timers_interface(NodeType && node_reference) diff --git a/rclcpp/include/rclcpp/node_interfaces/get_node_topics_interface.hpp b/rclcpp/include/rclcpp/node_interfaces/get_node_topics_interface.hpp index 2c7ccd543b..c84234282f 100644 --- a/rclcpp/include/rclcpp/node_interfaces/get_node_topics_interface.hpp +++ b/rclcpp/include/rclcpp/node_interfaces/get_node_topics_interface.hpp @@ -123,16 +123,18 @@ template< typename std::enable_if::value, int>::type = 0 > rclcpp::node_interfaces::NodeTopicsInterface * -get_node_topics_interface(NodeType && node_pointer) +get_node_topics_interface(NodeType node_pointer) { // Forward pointers to detail implmentation directly. - return detail::get_node_topics_interface_from_pointer(std::forward(node_pointer)); + return detail::get_node_topics_interface_from_pointer(node_pointer); } /// Get the NodeTopicsInterface as a pointer from a "Node like" object. template< typename NodeType, - typename std::enable_if::value, int>::type = 0 + typename std::enable_if< + !std::is_pointer::type>::value, int + >::type = 0 > rclcpp::node_interfaces::NodeTopicsInterface * get_node_topics_interface(NodeType && node_reference) diff --git a/rclcpp/test/node_interfaces/test_get_node_interfaces.cpp b/rclcpp/test/node_interfaces/test_get_node_interfaces.cpp index f41d40061b..015cade1e4 100644 --- a/rclcpp/test/node_interfaces/test_get_node_interfaces.cpp +++ b/rclcpp/test/node_interfaces/test_get_node_interfaces.cpp @@ -85,6 +85,26 @@ TEST_F(TestGetNodeInterfaces, node_reference) { >::value, "expected rclcpp::node_interfaces::NodeTopicsInterface *"); } +TEST_F(TestGetNodeInterfaces, rclcpp_node_pointer) { + rclcpp::Node * node_pointer = this->node.get(); + auto result = rclcpp::node_interfaces::get_node_topics_interface(node_pointer); + static_assert( + std::is_same< + rclcpp::node_interfaces::NodeTopicsInterface *, + decltype(result) + >::value, "expected rclcpp::node_interfaces::NodeTopicsInterface *"); +} + +TEST_F(TestGetNodeInterfaces, node_pointer) { + NodeWrapper * wrapped_node_pointer = this->wrapped_node.get(); + auto result = rclcpp::node_interfaces::get_node_topics_interface(wrapped_node_pointer); + static_assert( + std::is_same< + rclcpp::node_interfaces::NodeTopicsInterface *, + decltype(result) + >::value, "expected rclcpp::node_interfaces::NodeTopicsInterface *"); +} + TEST_F(TestGetNodeInterfaces, interface_shared_pointer) { std::shared_ptr interface_shared_ptr = this->node->get_node_topics_interface();