Skip to content

Commit

Permalink
Provide UniquePtr macros (moveit#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
v4hn authored and rhaschke committed Nov 24, 2019
1 parent e458308 commit 6770960
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
4 changes: 1 addition & 3 deletions moveit_core/macros/include/moveit/macros/class_forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@

/**
* \def MOVEIT_CLASS_FORWARD
* Macro that forward declares a class and defines two shared ptrs types:
* - ${Class}Ptr = shared_ptr<${Class}>
* - ${Class}ConstPtr = shared_ptr<const ${Class}>
* Macro that forward declares a class and defines the respective smartpointers through MOVEIT_DECLARE_PTR.
*/

#define MOVEIT_CLASS_FORWARD(C) \
Expand Down
25 changes: 15 additions & 10 deletions moveit_core/macros/include/moveit/macros/declare_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
/**
* \def MOVEIT_DELCARE_PTR
* Macro that given a Name and a Type declares the following types:
* - ${Name}Ptr = shared_ptr<${Type}>
* - ${Name}ConstPtr = shared_ptr<const ${Type}>
* - ${Name}Ptr = shared_ptr<${Type}>
* - ${Name}ConstPtr = shared_ptr<const ${Type}>
* - ${Name}WeakPtr = weak_ptr<${Type}>
* - ${Name}ConstWeakPtr = weak_ptr<const ${Type}>
* - ${Name}UniquePtr = unique_ptr<${Type}>
* - ${Name}ConstUniquePtr = unique_ptr<const ${Type}>
*
* For best portability the exact type of shared_ptr declared by the macro
* should be considered to be an implementation detail, liable to change in
Expand All @@ -52,23 +56,24 @@
typedef std::shared_ptr<Type> Name##Ptr; \
typedef std::shared_ptr<const Type> Name##ConstPtr; \
typedef std::weak_ptr<Type> Name##WeakPtr; \
typedef std::weak_ptr<const Type> Name##ConstWeakPtr;
typedef std::weak_ptr<const Type> Name##ConstWeakPtr; \
typedef std::unique_ptr<Type> Name##UniquePtr; \
typedef std::unique_ptr<const Type> Name##ConstUniquePtr;

/**
* \def MOVEIT_DELCARE_PTR_MEMBER
* Macro that given a Type declares the following types:
* - Ptr = shared_ptr<${Type}>
* - ConstPtr = shared_ptr<const ${Type}>
* The macro defines the same typedefs as MOVEIT_DECLARE_PTR, but shortens the new names to their suffix.
*
* This macro is intended for declaring the pointer typedefs as members of a
* class template. In other situations, MOVEIT_CLASS_FORWARD and
* MOVEIT_DECLARE_PTR should be preferred.
* This can be used to create `Classname::Ptr` style names, but in most situations in MoveIt's codebase,
* MOVEIT_CLASS_FORWARD and MOVEIT_DECLARE_PTR should be preferred.
*/

#define MOVEIT_DECLARE_PTR_MEMBER(Type) \
typedef std::shared_ptr<Type> Ptr; \
typedef std::shared_ptr<const Type> ConstPtr; \
typedef std::weak_ptr<Type> WeakPtr; \
typedef std::weak_ptr<const Type> ConstWeakPtr;
typedef std::weak_ptr<const Type> ConstWeakPtr; \
typedef std::unique_ptr<Type> UniquePtr; \
typedef std::unique_ptr<const Type> ConstUniquePtr;

#endif

0 comments on commit 6770960

Please sign in to comment.