Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DART_COMMON_DECLARE_SMART_POINTERS macro #1022

Merged
merged 10 commits into from
Mar 16, 2018
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Common

* Added DART_COMMON_MAKE_POINTERS macro: [#1022](https://github.com/dartsim/dart/pull/1022)
* Added ResourceRetriever::getFilePath(): [#972](https://github.com/dartsim/dart/pull/972)

* Kinematics/Dynamics
Expand Down
4 changes: 4 additions & 0 deletions dart/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ install(
DESTINATION include/dart/common/detail
COMPONENT headers
)

dart_format_add(
SmartPointer.hpp
)
25 changes: 19 additions & 6 deletions dart/common/SmartPointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,27 @@

#include <memory>

// Deprecated in DART 6.4
// -- Standard shared/weak pointers --
// Define a typedef for const and non-const version of shared_ptr and weak_ptr
// for the class X
#define DART_COMMON_MAKE_SHARED_WEAK( X )\
class X ;\
typedef std::shared_ptr< X > X ## Ptr;\
typedef std::shared_ptr< const X > Const ## X ## Ptr;\
typedef std::weak_ptr< X > Weak ## X ## Ptr;\
typedef std::weak_ptr< const X > WeakConst ## X ## Ptr;
#define DART_COMMON_MAKE_SHARED_WEAK(X) \
class X; \
using X##Ptr = std::shared_ptr<X>; \
using Const##X##Ptr = std::shared_ptr<const X>; \
using Weak##X##Ptr = std::weak_ptr<X>; \
using WeakConst##X##Ptr = std::weak_ptr<const X>;

// -- Standard shared/weak/unique pointers --
// Type aliases for const and non-const version of shared_ptr, weak_ptr, and
// unique_ptr for the class X
#define DART_COMMON_MAKE_POINTERS(X) \
class X; \
using X##Ptr = std::shared_ptr<X>; \
using Const##X##Ptr = std::shared_ptr<const X>; \
using Weak##X##Ptr = std::weak_ptr<X>; \
using WeakConst##X##Ptr = std::weak_ptr<const X>; \
using Unique##X##Ptr = std::unique_ptr<X>; \
using UniqueConst##X##Ptr = std::unique_ptr<const X>;

#endif // DART_COMMON_SMARTPOINTER_HPP_