rclcpp  master
C++ ROS Client Library API
get_node_graph_interface.hpp
Go to the documentation of this file.
1 // Copyright 2020 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 
16 #ifndef RCLCPP__NODE_INTERFACES__GET_NODE_GRAPH_INTERFACE_HPP_
17 #define RCLCPP__NODE_INTERFACES__GET_NODE_GRAPH_INTERFACE_HPP_
18 
19 #include <memory>
20 #include <utility>
21 #include <type_traits>
22 
23 #include "rcpputils/pointer_traits.hpp"
24 
27 
28 
30 
38 namespace rclcpp
39 {
40 namespace node_interfaces
41 {
42 namespace detail
43 {
44 
45 // If NodeType has a method called get_node_graph_interface() which returns a shared pointer.
46 template<
47  typename NodeType,
48  typename std::enable_if<has_node_graph_interface<
49  typename rcpputils::remove_pointer<NodeType>::type
50  >::value, int>::type = 0
51 >
54 {
55  if (!node_pointer) {
56  throw std::invalid_argument("node cannot be nullptr");
57  }
58  return node_pointer->get_node_graph_interface();
59 }
60 
61 } // namespace detail
62 
64 template<
65  typename NodeType,
66  typename std::enable_if<
67  rcpputils::is_pointer<NodeType>::value, int
68  >::type = 0
69 >
70 inline
72 get_node_graph_interface(NodeType && node)
73 {
74  // Forward pointers to detail implementation directly.
76 }
77 
79 template<
80  typename NodeType,
81  typename std::enable_if<
82  !rcpputils::is_pointer<NodeType>::value, int
83  >::type = 0
84 >
85 inline
87 get_node_graph_interface(NodeType && node)
88 {
89  // Forward references to detail implementation as a pointer.
91 }
92 
94 inline
98 {
99  return node_interface;
100 }
101 
102 } // namespace node_interfaces
103 } // namespace rclcpp
104 
105 #endif // RCLCPP__NODE_INTERFACES__GET_NODE_GRAPH_INTERFACE_HPP_
rclcpp::node_interfaces::get_node_graph_interface
std::shared_ptr< rclcpp::node_interfaces::NodeGraphInterface > get_node_graph_interface(NodeType &&node)
Get the NodeGraphInterface as a shared pointer from a pointer to a "Node like" object.
Definition: get_node_graph_interface.hpp:72
node_graph_interface.hpp
std::shared_ptr
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
std::enable_if
rclcpp::node_interfaces::detail::get_node_graph_interface_from_pointer
std::shared_ptr< rclcpp::node_interfaces::NodeGraphInterface > get_node_graph_interface_from_pointer(NodeType node_pointer)
Definition: get_node_graph_interface.hpp:53
std::invalid_argument
node_graph_interface_traits.hpp