Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions rclcpp/include/rclcpp/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
*
* Use in the private section of the class.
*/
#define RCLCPP_DISABLE_COPY(Class) \
Class(const Class &) = delete; \
Class & operator=(const Class &) = delete;
#define RCLCPP_DISABLE_COPY(...) \
__VA_ARGS__(const __VA_ARGS__ &) = delete; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird to me. The template accepts multiple arguments now (e.g. Foo, Bar) which then ends up as const Foo, Bar &?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I wasn't sure how else to allow passing a class with multiple template arguments to these macros.

__VA_ARGS__ & operator=(const __VA_ARGS__ &) = delete;

/* Defines aliases and static functions for using the Class with smart pointers.
*
* Use in the public section of the class.
* Make sure to include <memory> in the header when using this.
*/
#define RCLCPP_SMART_PTR_DEFINITIONS(Class) \
RCLCPP_SHARED_PTR_DEFINITIONS(Class) \
RCLCPP_WEAK_PTR_DEFINITIONS(Class) \
RCLCPP_UNIQUE_PTR_DEFINITIONS(Class)
#define RCLCPP_SMART_PTR_DEFINITIONS(...) \
RCLCPP_SHARED_PTR_DEFINITIONS(__VA_ARGS__) \
RCLCPP_WEAK_PTR_DEFINITIONS(__VA_ARGS__) \
RCLCPP_UNIQUE_PTR_DEFINITIONS(__VA_ARGS__)

/* Defines aliases and static functions for using the Class with smart pointers.
*
Expand All @@ -42,44 +42,44 @@
* Use in the public section of the class.
* Make sure to include <memory> in the header when using this.
*/
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(Class) \
RCLCPP_SHARED_PTR_DEFINITIONS(Class) \
RCLCPP_WEAK_PTR_DEFINITIONS(Class) \
__RCLCPP_UNIQUE_PTR_ALIAS(Class)
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...) \
RCLCPP_SHARED_PTR_DEFINITIONS(__VA_ARGS__) \
RCLCPP_WEAK_PTR_DEFINITIONS(__VA_ARGS__) \
__RCLCPP_UNIQUE_PTR_ALIAS(__VA_ARGS__)

#define __RCLCPP_SHARED_PTR_ALIAS(Class) using SharedPtr = std::shared_ptr<Class>;
#define __RCLCPP_SHARED_PTR_ALIAS(...) using SharedPtr = std::shared_ptr<__VA_ARGS__>;

#define __RCLCPP_MAKE_SHARED_DEFINITION(Class) \
#define __RCLCPP_MAKE_SHARED_DEFINITION(...) \
template<typename ... Args> \
static std::shared_ptr<Class> \
static std::shared_ptr<__VA_ARGS__> \
make_shared(Args && ... args) \
{ \
return std::make_shared<Class>(std::forward<Args>(args) ...); \
return std::make_shared<__VA_ARGS__>(std::forward<Args>(args) ...); \
}

/// Defines aliases and static functions for using the Class with shared_ptrs.
#define RCLCPP_SHARED_PTR_DEFINITIONS(Class) \
__RCLCPP_SHARED_PTR_ALIAS(Class) \
__RCLCPP_MAKE_SHARED_DEFINITION(Class)
#define RCLCPP_SHARED_PTR_DEFINITIONS(...) \
__RCLCPP_SHARED_PTR_ALIAS(__VA_ARGS__) \
__RCLCPP_MAKE_SHARED_DEFINITION(__VA_ARGS__)

#define __RCLCPP_WEAK_PTR_ALIAS(Class) using WeakPtr = std::weak_ptr<Class>;
#define __RCLCPP_WEAK_PTR_ALIAS(...) using WeakPtr = std::weak_ptr<__VA_ARGS__>;

/// Defines aliases and static functions for using the Class with weak_ptrs.
#define RCLCPP_WEAK_PTR_DEFINITIONS(Class) __RCLCPP_WEAK_PTR_ALIAS(Class)
#define RCLCPP_WEAK_PTR_DEFINITIONS(...) __RCLCPP_WEAK_PTR_ALIAS(__VA_ARGS__)

#define __RCLCPP_UNIQUE_PTR_ALIAS(Class) using UniquePtr = std::unique_ptr<Class>;
#define __RCLCPP_UNIQUE_PTR_ALIAS(...) using UniquePtr = std::unique_ptr<__VA_ARGS__>;

#define __RCLCPP_MAKE_UNIQUE_DEFINITION(Class) \
#define __RCLCPP_MAKE_UNIQUE_DEFINITION(...) \
template<typename ... Args> \
static std::unique_ptr<Class> \
static std::unique_ptr<__VA_ARGS__> \
make_unique(Args && ... args) \
{ \
return std::unique_ptr<Class>(new Class(std::forward<Args>(args) ...)); \
return std::unique_ptr<__VA_ARGS__>(new __VA_ARGS__(std::forward<Args>(args) ...)); \
}
/// Defines aliases and static functions for using the Class with unique_ptrs.
#define RCLCPP_UNIQUE_PTR_DEFINITIONS(Class) \
__RCLCPP_UNIQUE_PTR_ALIAS(Class) \
__RCLCPP_MAKE_UNIQUE_DEFINITION(Class)
#define RCLCPP_UNIQUE_PTR_DEFINITIONS(...) \
__RCLCPP_UNIQUE_PTR_ALIAS(__VA_ARGS__) \
__RCLCPP_MAKE_UNIQUE_DEFINITION(__VA_ARGS__)

#define RCLCPP_INFO(Args) std::cout << Args << std::endl;

Expand Down