From 677539bb075f34a8f5276eeed1f3a5341969c678 Mon Sep 17 00:00:00 2001 From: Mark Moll <mmoll@rice.edu> Date: Mon, 17 Feb 2014 12:30:37 -0600 Subject: [PATCH] return shared_pointer to const for const methods --- include/fcl/collision_object.h | 32 +++++++++++++++--------------- src/broadphase/broadphase_SSaP.cpp | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/fcl/collision_object.h b/include/fcl/collision_object.h index 043cfb9c..f23a8984 100644 --- a/include/fcl/collision_object.h +++ b/include/fcl/collision_object.h @@ -69,7 +69,7 @@ public: /// @brief get the type of the object virtual OBJECT_TYPE getObjectType() const { return OT_UNKNOWN; } - /// @brief get the node type + /// @brief get the node type virtual NODE_TYPE getNodeType() const { return BV_UNKNOWN; } /// @brief compute the AABB for object in local coordinate @@ -150,29 +150,27 @@ public: class CollisionObject { public: - CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_) : cgeom(cgeom_) + CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_) : + cgeom(cgeom_), cgeom_const(cgeom_) { cgeom->computeLocalAABB(); computeAABB(); } - CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_, const Transform3f& tf) : cgeom(cgeom_), t(tf) + CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_, const Transform3f& tf) : + cgeom(cgeom_), cgeom_const(cgeom_), t(tf) { cgeom->computeLocalAABB(); computeAABB(); } CollisionObject(const boost::shared_ptr<CollisionGeometry> &cgeom_, const Matrix3f& R, const Vec3f& T): - cgeom(cgeom_), t(Transform3f(R, T)) + cgeom(cgeom_), cgeom_const(cgeom_), t(Transform3f(R, T)) { cgeom->computeLocalAABB(); computeAABB(); } - CollisionObject() - { - } - ~CollisionObject() { } @@ -302,9 +300,9 @@ public: } /// @brief get geometry from the object instance - boost::shared_ptr<const CollisionGeometry> collisionGeometry() const + const boost::shared_ptr<const CollisionGeometry>& collisionGeometry() const { - return cgeom; + return cgeom_const; } /// @brief get object's cost density @@ -340,6 +338,7 @@ public: protected: boost::shared_ptr<CollisionGeometry> cgeom; + boost::shared_ptr<const CollisionGeometry> cgeom_const; Transform3f t; @@ -355,16 +354,16 @@ protected: class ContinuousCollisionObject { public: - ContinuousCollisionObject(const boost::shared_ptr<CollisionGeometry>& cgeom_) : cgeom(cgeom_) + ContinuousCollisionObject(const boost::shared_ptr<CollisionGeometry>& cgeom_) : + cgeom(cgeom_), cgeom_const(cgeom_) { } - ContinuousCollisionObject(const boost::shared_ptr<CollisionGeometry>& cgeom_, const boost::shared_ptr<MotionBase>& motion_) : cgeom(cgeom_), motion(motion_) + ContinuousCollisionObject(const boost::shared_ptr<CollisionGeometry>& cgeom_, const boost::shared_ptr<MotionBase>& motion_) : + cgeom(cgeom_), cgeom_const(cgeom), motion(motion_) { } - ContinuousCollisionObject() {} - ~ContinuousCollisionObject() {} /// @brief get the type of the object @@ -450,14 +449,15 @@ public: } /// @brief get geometry from the object instance - inline boost::shared_ptr<const CollisionGeometry> collisionGeometry() const + inline const boost::shared_ptr<const CollisionGeometry>& collisionGeometry() const { - return cgeom; + return cgeom_const; } protected: boost::shared_ptr<CollisionGeometry> cgeom; + boost::shared_ptr<const CollisionGeometry> cgeom_const; boost::shared_ptr<MotionBase> motion; diff --git a/src/broadphase/broadphase_SSaP.cpp b/src/broadphase/broadphase_SSaP.cpp index ea23055e..e0d766e4 100644 --- a/src/broadphase/broadphase_SSaP.cpp +++ b/src/broadphase/broadphase_SSaP.cpp @@ -78,7 +78,7 @@ struct SortByZLow class DummyCollisionObject : public CollisionObject { public: - DummyCollisionObject(const AABB& aabb_) : CollisionObject() + DummyCollisionObject(const AABB& aabb_) : CollisionObject(boost::shared_ptr<CollisionGeometry>()) { aabb = aabb_; } -- GitLab