rclcpp  master
C++ ROS Client Library API
macros.hpp
Go to the documentation of this file.
1 // Copyright 2014 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 #include <memory>
16 #include <utility>
17 
18 #ifndef RCLCPP__MACROS_HPP_
19 #define RCLCPP__MACROS_HPP_
20 
26 #define RCLCPP_DISABLE_COPY(...) \
27  __VA_ARGS__(const __VA_ARGS__ &) = delete; \
28  __VA_ARGS__ & operator=(const __VA_ARGS__ &) = delete;
29 
36 #define RCLCPP_SMART_PTR_DEFINITIONS(...) \
37  RCLCPP_SHARED_PTR_DEFINITIONS(__VA_ARGS__) \
38  RCLCPP_WEAK_PTR_DEFINITIONS(__VA_ARGS__) \
39  RCLCPP_UNIQUE_PTR_DEFINITIONS(__VA_ARGS__)
40 
51 #define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...) \
52  RCLCPP_SHARED_PTR_DEFINITIONS(__VA_ARGS__) \
53  RCLCPP_WEAK_PTR_DEFINITIONS(__VA_ARGS__) \
54  __RCLCPP_UNIQUE_PTR_ALIAS(__VA_ARGS__)
55 
66 #define RCLCPP_SMART_PTR_ALIASES_ONLY(...) \
67  __RCLCPP_SHARED_PTR_ALIAS(__VA_ARGS__) \
68  __RCLCPP_WEAK_PTR_ALIAS(__VA_ARGS__) \
69  __RCLCPP_MAKE_SHARED_DEFINITION(__VA_ARGS__)
70 
71 #define __RCLCPP_SHARED_PTR_ALIAS(...) \
72  using SharedPtr = std::shared_ptr<__VA_ARGS__>; \
73  using ConstSharedPtr = std::shared_ptr<const __VA_ARGS__>;
74 
75 #define __RCLCPP_MAKE_SHARED_DEFINITION(...) \
76  template<typename ... Args> \
77  static std::shared_ptr<__VA_ARGS__> \
78  make_shared(Args && ... args) \
79  { \
80  return std::make_shared<__VA_ARGS__>(std::forward<Args>(args) ...); \
81  }
82 
84 #define RCLCPP_SHARED_PTR_DEFINITIONS(...) \
85  __RCLCPP_SHARED_PTR_ALIAS(__VA_ARGS__) \
86  __RCLCPP_MAKE_SHARED_DEFINITION(__VA_ARGS__)
87 
88 #define __RCLCPP_WEAK_PTR_ALIAS(...) \
89  using WeakPtr = std::weak_ptr<__VA_ARGS__>; \
90  using ConstWeakPtr = std::weak_ptr<const __VA_ARGS__>;
91 
93 #define RCLCPP_WEAK_PTR_DEFINITIONS(...) __RCLCPP_WEAK_PTR_ALIAS(__VA_ARGS__)
94 
95 #define __RCLCPP_UNIQUE_PTR_ALIAS(...) using UniquePtr = std::unique_ptr<__VA_ARGS__>;
96 
97 #define __RCLCPP_MAKE_UNIQUE_DEFINITION(...) \
98  template<typename ... Args> \
99  static std::unique_ptr<__VA_ARGS__> \
100  make_unique(Args && ... args) \
101  { \
102  return std::unique_ptr<__VA_ARGS__>(new __VA_ARGS__(std::forward<Args>(args) ...)); \
103  }
104 
106 #define RCLCPP_UNIQUE_PTR_DEFINITIONS(...) \
107  __RCLCPP_UNIQUE_PTR_ALIAS(__VA_ARGS__) \
108  __RCLCPP_MAKE_UNIQUE_DEFINITION(__VA_ARGS__)
109 
110 #define RCLCPP_STRING_JOIN(arg1, arg2) RCLCPP_DO_STRING_JOIN(arg1, arg2)
111 #define RCLCPP_DO_STRING_JOIN(arg1, arg2) arg1 ## arg2
112 
113 #endif // RCLCPP__MACROS_HPP_