Skip to content

Commit

Permalink
Add DART_COMMON_DECLARE_SMART_POINTERS macro (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Mar 16, 2018
1 parent 2f40699 commit 9b39dea
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 84 deletions.
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_DECLARE_SMART_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/collision/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ add_subdirectory(dart)
add_subdirectory(fcl)
add_subdirectory(ode)
add_subdirectory(bullet)

dart_format_add(
SmartPointer.hpp
)
17 changes: 8 additions & 9 deletions dart/collision/SmartPointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@
#ifndef DART_COLLISION_SMARTPOINTER_HPP_
#define DART_COLLISION_SMARTPOINTER_HPP_

#include "dart/config.hpp"
#include "dart/common/SmartPointer.hpp"

namespace dart {
namespace collision {

DART_COMMON_MAKE_SHARED_WEAK(CollisionDetector)
DART_COMMON_MAKE_SHARED_WEAK(FCLCollisionDetector)
DART_COMMON_MAKE_SHARED_WEAK(DARTCollisionDetector)
DART_COMMON_DECLARE_SHARED_WEAK(CollisionDetector)
DART_COMMON_DECLARE_SHARED_WEAK(FCLCollisionDetector)
DART_COMMON_DECLARE_SHARED_WEAK(DARTCollisionDetector)

DART_COMMON_MAKE_SHARED_WEAK(CollisionObject)
DART_COMMON_MAKE_SHARED_WEAK(CollisionGroup)
DART_COMMON_DECLARE_SHARED_WEAK(CollisionObject)
DART_COMMON_DECLARE_SHARED_WEAK(CollisionGroup)

} // namespace collision
} // namespace dart
} // namespace collision
} // namespace dart

#endif // DART_COLLISION_SMARTPOINTER_HPP_
#endif // DART_COLLISION_SMARTPOINTER_HPP_
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
)
27 changes: 21 additions & 6 deletions dart/common/SmartPointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,26 @@
// -- 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_DECLARE_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>;

// Deprecated in DART 6.4. Please use DART_COMMON_DECLARE_SHARED_WEAK
//
// -- 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) DART_COMMON_DECLARE_SHARED_WEAK(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_DECLARE_SMART_POINTERS(X) \
DART_COMMON_DECLARE_SHARED_WEAK(X) \
using Unique##X##Ptr = std::unique_ptr<X>; \
using UniqueConst##X##Ptr = std::unique_ptr<const X>;

#endif // DART_COMMON_SMARTPOINTER_HPP_
4 changes: 4 additions & 0 deletions dart/constraint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ install(
DESTINATION include/dart/constraint
COMPONENT headers
)

dart_format_add(
SmartPointer.hpp
)
30 changes: 15 additions & 15 deletions dart/constraint/SmartPointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@
namespace dart {
namespace constraint {

DART_COMMON_MAKE_SHARED_WEAK(ConstrainedGroup)
DART_COMMON_MAKE_SHARED_WEAK(ConstraintBase)
DART_COMMON_MAKE_SHARED_WEAK(ClosedLoopConstraint)
DART_COMMON_MAKE_SHARED_WEAK(ContactConstraint)
DART_COMMON_MAKE_SHARED_WEAK(SoftContactConstraint)
DART_COMMON_MAKE_SHARED_WEAK(JointLimitConstraint)
DART_COMMON_MAKE_SHARED_WEAK(ServoMotorConstraint)
DART_COMMON_MAKE_SHARED_WEAK(JointCoulombFrictionConstraint)
DART_COMMON_MAKE_SHARED_WEAK(JointConstraint)
DART_COMMON_MAKE_SHARED_WEAK(LCPSolver)

DART_COMMON_MAKE_SHARED_WEAK(BallJointConstraint)
DART_COMMON_MAKE_SHARED_WEAK(WeldJointConstraint)

DART_COMMON_MAKE_SHARED_WEAK(BalanceConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(ConstrainedGroup)
DART_COMMON_DECLARE_SHARED_WEAK(ConstraintBase)
DART_COMMON_DECLARE_SHARED_WEAK(ClosedLoopConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(ContactConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(SoftContactConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(JointLimitConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(ServoMotorConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(JointCoulombFrictionConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(JointConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(LCPSolver)

DART_COMMON_DECLARE_SHARED_WEAK(BallJointConstraint)
DART_COMMON_DECLARE_SHARED_WEAK(WeldJointConstraint)

DART_COMMON_DECLARE_SHARED_WEAK(BalanceConstraint)

} // namespace constraint
} // namespace dart
Expand Down
4 changes: 4 additions & 0 deletions dart/dynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ dart_format_add(
detail/TranslationalJoint2DAspect.hpp
detail/TranslationalJoint2DAspect.cpp
)

dart_format_add(
SmartPointer.hpp
)
106 changes: 52 additions & 54 deletions dart/dynamics/SmartPointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

#include "dart/common/SmartPointer.hpp"
#include "dart/dynamics/detail/BodyNodePtr.hpp"
#include "dart/dynamics/detail/JointPtr.hpp"
#include "dart/dynamics/detail/DegreeOfFreedomPtr.hpp"
#include "dart/dynamics/detail/NodePtr.hpp"
#include "dart/dynamics/detail/InverseKinematicsPtr.hpp"
#include "dart/dynamics/detail/JointPtr.hpp"
#include "dart/dynamics/detail/NodePtr.hpp"

// This file is a lightweight means of providing the smart pointers which are
// commonly used within the dart::dynamics namespace. It is 'lightweight' in the
Expand All @@ -49,55 +49,54 @@
namespace dart {
namespace dynamics {

DART_COMMON_MAKE_SHARED_WEAK(ShapeFrame)
DART_COMMON_MAKE_SHARED_WEAK(SimpleFrame)
DART_COMMON_DECLARE_SHARED_WEAK(ShapeFrame)
DART_COMMON_DECLARE_SHARED_WEAK(SimpleFrame)

DART_COMMON_MAKE_SHARED_WEAK(NodeDestructor)
DART_COMMON_DECLARE_SHARED_WEAK(NodeDestructor)

//-----------------------------------------------------------------------------
// Skeleton Smart Pointers
//-----------------------------------------------------------------------------
DART_COMMON_MAKE_SHARED_WEAK(Skeleton)
DART_COMMON_DECLARE_SHARED_WEAK(Skeleton)
// These pointers will take the form of:
// std::shared_ptr<Skeleton> --> SkeletonPtr
// std::shared_ptr<const Skeleton> --> ConstSkeletonPtr
// std::weak_ptr<Skeleton> --> WeakSkeletonPtr
// std::weak_ptr<const Skeleton> --> WeakConstSkeletonPtr

// MetaSkeleton smart pointers
DART_COMMON_MAKE_SHARED_WEAK(MetaSkeleton)
DART_COMMON_DECLARE_SHARED_WEAK(MetaSkeleton)

// ReferentialSkeleton smart pointers
DART_COMMON_MAKE_SHARED_WEAK(ReferentialSkeleton)
DART_COMMON_DECLARE_SHARED_WEAK(ReferentialSkeleton)

DART_COMMON_MAKE_SHARED_WEAK(Group)
DART_COMMON_MAKE_SHARED_WEAK(Linkage)
DART_COMMON_MAKE_SHARED_WEAK(Branch)
DART_COMMON_MAKE_SHARED_WEAK(Chain)
DART_COMMON_DECLARE_SHARED_WEAK(Group)
DART_COMMON_DECLARE_SHARED_WEAK(Linkage)
DART_COMMON_DECLARE_SHARED_WEAK(Branch)
DART_COMMON_DECLARE_SHARED_WEAK(Chain)

//-----------------------------------------------------------------------------
// Shape Smart Pointers
//-----------------------------------------------------------------------------
DART_COMMON_MAKE_SHARED_WEAK(Shape)
DART_COMMON_MAKE_SHARED_WEAK(ArrowShape)
DART_COMMON_MAKE_SHARED_WEAK(BoxShape)
DART_COMMON_MAKE_SHARED_WEAK(CylinderShape)
DART_COMMON_MAKE_SHARED_WEAK(EllipsoidShape)
DART_COMMON_MAKE_SHARED_WEAK(LineSegmentShape)
DART_COMMON_MAKE_SHARED_WEAK(MeshShape)
DART_COMMON_MAKE_SHARED_WEAK(PlaneShape)
DART_COMMON_MAKE_SHARED_WEAK(SoftMeshShape)

DART_COMMON_DECLARE_SHARED_WEAK(Shape)
DART_COMMON_DECLARE_SHARED_WEAK(ArrowShape)
DART_COMMON_DECLARE_SHARED_WEAK(BoxShape)
DART_COMMON_DECLARE_SHARED_WEAK(CylinderShape)
DART_COMMON_DECLARE_SHARED_WEAK(EllipsoidShape)
DART_COMMON_DECLARE_SHARED_WEAK(LineSegmentShape)
DART_COMMON_DECLARE_SHARED_WEAK(MeshShape)
DART_COMMON_DECLARE_SHARED_WEAK(PlaneShape)
DART_COMMON_DECLARE_SHARED_WEAK(SoftMeshShape)

//-----------------------------------------------------------------------------
// BodyNode Smart Pointers
//-----------------------------------------------------------------------------
#define DART_DYNAMICS_MAKE_BODYNODEPTR( X ) \
class X ; \
typedef TemplateBodyNodePtr< X > X ## Ptr; \
typedef TemplateBodyNodePtr< const X > Const ## X ## Ptr; \
typedef TemplateWeakBodyNodePtr< X > Weak ## X ## Ptr; \
typedef TemplateWeakBodyNodePtr< const X > WeakConst ## X ## Ptr;
#define DART_DYNAMICS_MAKE_BODYNODEPTR(X) \
class X; \
using X##Ptr = TemplateBodyNodePtr<X>; \
using Const##X##Ptr = TemplateBodyNodePtr<const X>; \
using Weak##X##Ptr = TemplateWeakBodyNodePtr<X>; \
using WeakConst##X##Ptr = TemplateWeakBodyNodePtr<const X>;

// BodyNode smart pointers
DART_DYNAMICS_MAKE_BODYNODEPTR(BodyNode)
Expand All @@ -110,17 +109,15 @@ DART_DYNAMICS_MAKE_BODYNODEPTR(BodyNode)
// SoftBodyNode smart pointers
DART_DYNAMICS_MAKE_BODYNODEPTR(SoftBodyNode)


//-----------------------------------------------------------------------------
// BodyNode-dependent Smart Pointers
//-----------------------------------------------------------------------------
#define DART_DYNAMICS_MAKE_BN_DEPENDENT_PTR( X ) \
class X ; \
typedef Template ## X ## Ptr < X , BodyNode > X ## Ptr; \
typedef Template ## X ## Ptr < const X , const BodyNode > Const ## X ## Ptr; \
typedef TemplateWeak ## X ## Ptr < X , BodyNode > Weak ## X ## Ptr; \
typedef TemplateWeak ## X ## Ptr < const X , const BodyNode > WeakConst ## X ## Ptr;

#define DART_DYNAMICS_MAKE_BN_DEPENDENT_PTR(X) \
class X; \
using X##Ptr = Template##X##Ptr<X, BodyNode>; \
using Const##X##Ptr = Template##X##Ptr<const X, const BodyNode>; \
using Weak##X##Ptr = TemplateWeak##X##Ptr<X, BodyNode>; \
using WeakConst##X##Ptr = TemplateWeak##X##Ptr<const X, const BodyNode>;

// Joint smart pointers
DART_DYNAMICS_MAKE_BN_DEPENDENT_PTR(Joint)
Expand All @@ -133,21 +130,21 @@ DART_DYNAMICS_MAKE_BN_DEPENDENT_PTR(Joint)
// DegreeOfFreedom smart pointers
DART_DYNAMICS_MAKE_BN_DEPENDENT_PTR(DegreeOfFreedom)
// These pointers will take the form of:
// TemplateDegreeOfFreedomPtr<DegreeOfFreedom> --> DegreeOfFreedomPtr
// TemplateDegreeOfFreedomPtr<const DegreeOfFreedom> --> ConstDegreeOfFreedomPtr
// TemplateWeakDegreeOfFreedomPtr<DegreeOfFreedom> --> WeakDegreeOfFreedomPtr
// TemplateWeakDegreeOfFreedomPtr<const DegreeOfFreedom> --> WeakConstDegreeOfFreedomPtr

// TemplateDegreeOfFreedomPtr<DegreeOfFreedom> --> DegreeOfFreedomPtr
// TemplateDegreeOfFreedomPtr<const DegreeOfFreedom> --> ConstDegreeOfFreedomPtr
// TemplateWeakDegreeOfFreedomPtr<DegreeOfFreedom> --> WeakDegreeOfFreedomPtr
// TemplateWeakDegreeOfFreedomPtr<const DegreeOfFreedom>
// --> WeakConstDegreeOfFreedomPtr

//-----------------------------------------------------------------------------
// Node Smart Pointers
//-----------------------------------------------------------------------------
#define DART_DYNAMICS_MAKE_NODEPTR( X ) \
class X ; \
typedef TemplateNodePtr < X , BodyNode > X ## Ptr; \
typedef TemplateNodePtr < const X , const BodyNode > Const ## X ## Ptr; \
typedef TemplateWeakNodePtr < X , BodyNode > Weak ## X ## Ptr; \
typedef TemplateWeakNodePtr < const X , const BodyNode > WeakConst ## X ## Ptr;
#define DART_DYNAMICS_MAKE_NODEPTR(X) \
class X; \
using X##Ptr = TemplateNodePtr<X, BodyNode>; \
using Const##X##Ptr = TemplateNodePtr<const X, const BodyNode>; \
using Weak##X##Ptr = TemplateWeakNodePtr<X, BodyNode>; \
using WeakConst##X##Ptr = TemplateWeakNodePtr<const X, const BodyNode>;

DART_DYNAMICS_MAKE_NODEPTR(Node)
// These pointers will take the form of:
Expand All @@ -167,16 +164,17 @@ DART_DYNAMICS_MAKE_NODEPTR(EndEffector)

DART_DYNAMICS_MAKE_NODEPTR(ShapeNode)


//-----------------------------------------------------------------------------
// InverseKinematics Smart Pointers
//-----------------------------------------------------------------------------
#define DART_DYNAMICS_MAKE_IK_PTR( X ) \
class X ; \
typedef TemplateInverseKinematicsPtr< X , JacobianNodePtr > X ## Ptr; \
typedef TemplateInverseKinematicsPtr< const X , ConstJacobianNodePtr > Const ## X ## Ptr; \
typedef TemplateWeakInverseKinematicsPtr< X , JacobianNodePtr > Weak ## X ## Ptr; \
typedef TemplateWeakInverseKinematicsPtr< const X , ConstJacobianNodePtr > WeakConst ## X ## Ptr;
#define DART_DYNAMICS_MAKE_IK_PTR(X) \
class X; \
using X##Ptr = TemplateInverseKinematicsPtr<X, JacobianNodePtr>; \
using Const##X##Ptr \
= TemplateInverseKinematicsPtr<const X, ConstJacobianNodePtr>; \
using Weak##X##Ptr = TemplateWeakInverseKinematicsPtr<X, JacobianNodePtr>; \
using WeakConst##X##Ptr \
= TemplateWeakInverseKinematicsPtr<const X, ConstJacobianNodePtr>;

DART_DYNAMICS_MAKE_IK_PTR(InverseKinematics)

Expand Down

0 comments on commit 9b39dea

Please sign in to comment.