ROS 2 rclcpp + rcl - jazzy  jazzy
ROS 2 C++ Client Library with ROS Client Library
subscription_traits.hpp
1 // Copyright 2017 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__SUBSCRIPTION_TRAITS_HPP_
16 #define RCLCPP__SUBSCRIPTION_TRAITS_HPP_
17 
18 #include <memory>
19 
20 #include "rclcpp/function_traits.hpp"
21 #include "rclcpp/serialized_message.hpp"
22 #include "rclcpp/subscription_options.hpp"
23 #include "rcl/types.h"
24 
25 namespace rclcpp
26 {
27 
28 class QoS;
29 
30 namespace subscription_traits
31 {
32 
33 /*
34  * The current version of uncrustify has a misinterpretion here
35  * between `:` used for inheritance vs for initializer list
36  * The result is that whenever a templated struct is used,
37  * the colon has to be without any whitespace next to it whereas
38  * when no template is used, the colon has to be separated by a space.
39  * Cheers!
40  */
41 template<typename T>
42 struct is_serialized_subscription_argument : std::false_type
43 {};
44 
45 template<>
47 {};
48 
49 template<>
50 struct is_serialized_subscription_argument<std::shared_ptr<SerializedMessage>>
51  : std::true_type
52 {};
53 
54 template<typename T>
56 {};
57 
58 template<typename CallbackT>
61  typename rclcpp::function_traits::function_traits<CallbackT>::template argument_type<0>>
62 {};
63 
64 template<typename MessageT>
66 {
67  using type = typename std::remove_cv_t<std::remove_reference_t<MessageT>>;
68 };
69 
70 template<typename MessageT>
71 struct extract_message_type<std::shared_ptr<MessageT>>: extract_message_type<MessageT>
72 {};
73 
74 template<typename MessageT, typename Deleter>
75 struct extract_message_type<std::unique_ptr<MessageT, Deleter>>: extract_message_type<MessageT>
76 {};
77 
78 template<
79  typename CallbackT,
80  typename AllocatorT = std::allocator<void>,
81  // Do not attempt if CallbackT is an integer (mistaken for depth)
82  typename = std::enable_if_t<!std::is_integral<
83  std::remove_cv_t<std::remove_reference_t<CallbackT>>>::value>,
84  // Do not attempt if CallbackT is a QoS (mistaken for qos)
85  typename = std::enable_if_t<!std::is_base_of<
87  std::remove_cv_t<std::remove_reference_t<CallbackT>>>::value>,
88  // Do not attempt if CallbackT is a rmw_qos_profile_t (mistaken for qos profile)
89  typename = std::enable_if_t<!std::is_same<
90  rmw_qos_profile_t,
91  std::remove_cv_t<std::remove_reference_t<CallbackT>>>::value>,
92  // Do not attempt if CallbackT is a rclcpp::SubscriptionOptionsWithAllocator
93  typename = std::enable_if_t<!std::is_same<
95  std::remove_cv_t<std::remove_reference_t<CallbackT>>>::value>
96 >
98  typename rclcpp::function_traits::function_traits<CallbackT>::template argument_type<0>>
99 {};
100 
101 } // namespace subscription_traits
102 } // namespace rclcpp
103 
104 #endif // RCLCPP__SUBSCRIPTION_TRAITS_HPP_
Encapsulation of Quality of Service settings.
Definition: qos.hpp:116
Object oriented version of rcl_serialized_message_t with destructor to avoid memory leaks.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
Structure containing optional configuration for Subscriptions.