|
23 | 23 | Class(const Class &) = delete; \ |
24 | 24 | Class & operator=(const Class &) = delete; |
25 | 25 |
|
26 | | -/* Defines a make_shared static function on the class using perfect forwarding. |
| 26 | +/* Defines aliases and static functions for using the Class with smart pointers. |
27 | 27 | * |
28 | 28 | * Use in the public section of the class. |
29 | 29 | * Make sure to include <memory> in the header when using this. |
30 | 30 | */ |
31 | | -#define RCLCPP_MAKE_SHARED_DEFINITIONS(Class) \ |
32 | | - typedef std::shared_ptr<Class> SharedPtr; \ |
33 | | - \ |
| 31 | +#define RCLCPP_SMART_PTR_DEFINITIONS(Class) \ |
| 32 | + RCLCPP_SHARED_PTR_DEFINITIONS(Class) \ |
| 33 | + RCLCPP_WEAK_PTR_DEFINITIONS(Class) \ |
| 34 | + RCLCPP_UNIQUE_PTR_DEFINITIONS(Class) |
| 35 | + |
| 36 | +/* Defines aliases and static functions for using the Class with smart pointers. |
| 37 | + * |
| 38 | + * Same as RCLCPP_SMART_PTR_DEFINITIONS expect it excludes the static |
| 39 | + * Class::make_unique() method definition which does not work on classes which |
| 40 | + * are not CopyConstructable. |
| 41 | + * |
| 42 | + * Use in the public section of the class. |
| 43 | + * Make sure to include <memory> in the header when using this. |
| 44 | + */ |
| 45 | +#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Class) \ |
| 46 | + RCLCPP_SHARED_PTR_DEFINITIONS(Class) \ |
| 47 | + RCLCPP_WEAK_PTR_DEFINITIONS(Class) \ |
| 48 | + __RCLCPP_UNIQUE_PTR_ALIAS(Class) |
| 49 | + |
| 50 | +#define __RCLCPP_SHARED_PTR_ALIAS(Class) using SharedPtr = std::shared_ptr<Class>; |
| 51 | + |
| 52 | +#define __RCLCPP_MAKE_SHARED_DEFINITION(Class) \ |
34 | 53 | template<typename ... Args> \ |
35 | 54 | static std::shared_ptr<Class> \ |
36 | 55 | make_shared(Args && ... args) \ |
37 | 56 | { \ |
38 | 57 | return std::make_shared<Class>(std::forward<Args>(args) ...); \ |
39 | 58 | } |
40 | 59 |
|
| 60 | +/// Defines aliases and static functions for using the Class with shared_ptrs. |
| 61 | +#define RCLCPP_SHARED_PTR_DEFINITIONS(Class) \ |
| 62 | + __RCLCPP_SHARED_PTR_ALIAS(Class) \ |
| 63 | + __RCLCPP_MAKE_SHARED_DEFINITION(Class) |
| 64 | + |
| 65 | +#define __RCLCPP_WEAK_PTR_ALIAS(Class) using WeakPtr = std::weak_ptr<Class>; |
| 66 | + |
| 67 | +/// Defines aliases and static functions for using the Class with weak_ptrs. |
| 68 | +#define RCLCPP_WEAK_PTR_DEFINITIONS(Class) __RCLCPP_WEAK_PTR_ALIAS(Class) |
| 69 | + |
| 70 | +#define __RCLCPP_UNIQUE_PTR_ALIAS(Class) using UniquePtr = std::unique_ptr<Class>; |
| 71 | + |
| 72 | +#define __RCLCPP_MAKE_UNIQUE_DEFINITION(Class) \ |
| 73 | + template<typename ... Args> \ |
| 74 | + static std::unique_ptr<Class> \ |
| 75 | + make_unique(Args && ... args) \ |
| 76 | + { \ |
| 77 | + return std::unique_ptr<Class>(new Class(std::forward<Args>(args) ...)); \ |
| 78 | + } |
| 79 | +/// Defines aliases and static functions for using the Class with unique_ptrs. |
| 80 | +#define RCLCPP_UNIQUE_PTR_DEFINITIONS(Class) \ |
| 81 | + __RCLCPP_UNIQUE_PTR_ALIAS(Class) \ |
| 82 | + __RCLCPP_MAKE_UNIQUE_DEFINITION(Class) |
| 83 | + |
41 | 84 | #define RCLCPP_INFO(Args) std::cout << Args << std::endl; |
42 | 85 |
|
43 | 86 | #endif /* RCLCPP_RCLCPP_MACROS_HPP_ */ |
0 commit comments