rclcpp
master
C++ ROS Client Library API
include
rclcpp
node_interfaces
get_node_logging_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_LOGGING_INTERFACE_HPP_
17
#define RCLCPP__NODE_INTERFACES__GET_NODE_LOGGING_INTERFACE_HPP_
18
19
#include <memory>
20
#include <utility>
21
#include <type_traits>
22
23
#include "rcpputils/pointer_traits.hpp"
24
25
#include "
rclcpp/node_interfaces/node_logging_interface.hpp
"
26
#include "
rclcpp/node_interfaces/node_logging_interface_traits.hpp
"
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_logging_interface() which returns a shared pointer.
46
template
<
47
typename
NodeType,
48
typename
std::enable_if
<has_node_logging_interface<
49
typename
rcpputils::remove_pointer<NodeType>::type
50
>::value,
int
>::type = 0
51
>
52
std::shared_ptr<rclcpp::node_interfaces::NodeLoggingInterface>
53
get_node_logging_interface_from_pointer
(NodeType node_pointer)
54
{
55
if
(!node_pointer) {
56
throw
std::invalid_argument
(
"node cannot be nullptr"
);
57
}
58
return
node_pointer->get_node_logging_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
71
std::shared_ptr<rclcpp::node_interfaces::NodeLoggingInterface>
72
get_node_logging_interface
(NodeType && node)
73
{
74
// Forward pointers to detail implementation directly.
75
return
detail::get_node_logging_interface_from_pointer
(node);
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
86
std::shared_ptr<rclcpp::node_interfaces::NodeLoggingInterface>
87
get_node_logging_interface
(NodeType && node)
88
{
89
// Forward references to detail implementation as a pointer.
90
return
detail::get_node_logging_interface_from_pointer
(&node);
91
}
92
94
inline
95
std::shared_ptr<rclcpp::node_interfaces::NodeLoggingInterface>
96
get_node_logging_interface
(
97
std::shared_ptr<rclcpp::node_interfaces::NodeLoggingInterface>
& node_interface)
98
{
99
return
node_interface;
100
}
101
102
}
// namespace node_interfaces
103
}
// namespace rclcpp
104
105
#endif // RCLCPP__NODE_INTERFACES__GET_NODE_LOGGING_INTERFACE_HPP_
std::shared_ptr
node_logging_interface_traits.hpp
rclcpp
This header provides the get_node_base_interface() template function.
Definition:
allocator_common.hpp:24
std::enable_if
std::invalid_argument
rclcpp::node_interfaces::get_node_logging_interface
std::shared_ptr< rclcpp::node_interfaces::NodeLoggingInterface > get_node_logging_interface(NodeType &&node)
Get the NodeLoggingInterface as a shared pointer from a pointer to a "Node like" object.
Definition:
get_node_logging_interface.hpp:72
rclcpp::node_interfaces::detail::get_node_logging_interface_from_pointer
std::shared_ptr< rclcpp::node_interfaces::NodeLoggingInterface > get_node_logging_interface_from_pointer(NodeType node_pointer)
Definition:
get_node_logging_interface.hpp:53
node_logging_interface.hpp
Generated by
1.8.17