Skip to content

Commit

Permalink
Deprecate custom make_unique in favor of std::make_unique (dartsim#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored May 16, 2019
1 parent be05975 commit 968013c
Show file tree
Hide file tree
Showing 37 changed files with 100 additions and 99 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### [DART 6.9.0 (20XX-XX-XX)](https://github.com/dartsim/dart/milestone/52?closed=1)

* Common

* Deprecated custom make_unique in favor of std::make_unique: [#1317](https://github.com/dartsim/dart/pull/1317)

* Collision Detection

* Added raycast query to BulletCollisionDetector: [#1309](https://github.com/dartsim/dart/pull/1309)
Expand Down
54 changes: 27 additions & 27 deletions dart/collision/bullet/BulletCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const std::string& BulletCollisionDetector::getStaticType()
std::unique_ptr<CollisionGroup>
BulletCollisionDetector::createCollisionGroup()
{
return common::make_unique<BulletCollisionGroup>(shared_from_this());
return std::make_unique<BulletCollisionGroup>(shared_from_this());
}

//==============================================================================
Expand Down Expand Up @@ -491,9 +491,9 @@ BulletCollisionDetector::createBulletCollisionShape(
const auto sphere = static_cast<const SphereShape*>(shape.get());
const auto radius = sphere->getRadius();

auto bulletCollisionShape = common::make_unique<btSphereShape>(radius);
auto bulletCollisionShape = std::make_unique<btSphereShape>(radius);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<BoxShape>())
Expand All @@ -504,9 +504,9 @@ BulletCollisionDetector::createBulletCollisionShape(
const Eigen::Vector3d& size = box->getSize();

auto bulletCollisionShape
= common::make_unique<btBoxShape>(convertVector3(size*0.5));
= std::make_unique<btBoxShape>(convertVector3(size*0.5));

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<EllipsoidShape>())
Expand All @@ -519,7 +519,7 @@ BulletCollisionDetector::createBulletCollisionShape(
auto bulletCollisionShape = createBulletEllipsoidMesh(
radii[0]*2.0, radii[1]*2.0, radii[2]*2.0);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<CylinderShape>())
Expand All @@ -531,9 +531,9 @@ BulletCollisionDetector::createBulletCollisionShape(
const auto height = cylinder->getHeight();
const auto size = btVector3(radius, radius, height * 0.5);

auto bulletCollisionShape = common::make_unique<btCylinderShapeZ>(size);
auto bulletCollisionShape = std::make_unique<btCylinderShapeZ>(size);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<CapsuleShape>())
Expand All @@ -545,9 +545,9 @@ BulletCollisionDetector::createBulletCollisionShape(
const auto height = capsule->getHeight();

auto bulletCollisionShape
= common::make_unique<btCapsuleShapeZ>(radius, height);
= std::make_unique<btCapsuleShapeZ>(radius, height);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<ConeShape>())
Expand All @@ -559,14 +559,14 @@ BulletCollisionDetector::createBulletCollisionShape(
const auto height = cone->getHeight();

auto bulletCollisionShape
= common::make_unique<btConeShapeZ>(radius, height);
= std::make_unique<btConeShapeZ>(radius, height);
bulletCollisionShape->setMargin(0.0);
// TODO(JS): Bullet seems to use constant margin 0.4, however this could be
// dangerous when the cone is sufficiently small. We use zero margin here
// until find better solution even using zero margin is not recommended:
// https://www.sjbaker.org/wiki/index.php?title=Physics_-_Bullet_Collected_random_advice#Minimum_object_sizes_-_by_Erwin

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<PlaneShape>())
Expand All @@ -577,10 +577,10 @@ BulletCollisionDetector::createBulletCollisionShape(
const Eigen::Vector3d normal = plane->getNormal();
const double offset = plane->getOffset();

auto bulletCollisionShape = common::make_unique<btStaticPlaneShape>(
auto bulletCollisionShape = std::make_unique<btStaticPlaneShape>(
convertVector3(normal), offset);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<MultiSphereConvexHullShape>())
Expand All @@ -601,10 +601,10 @@ BulletCollisionDetector::createBulletCollisionShape(
bulletPositions[i] = convertVector3(spheres[i].second);
}

auto bulletCollisionShape = common::make_unique<btMultiSphereShape>(
auto bulletCollisionShape = std::make_unique<btMultiSphereShape>(
bulletPositions.data(), bulletRadii.data(), numSpheres);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<MeshShape>())
Expand All @@ -618,7 +618,7 @@ BulletCollisionDetector::createBulletCollisionShape(
auto bulletCollisionShape = createBulletCollisionShapeFromAssimpScene(
scale, mesh);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<SoftMeshShape>())
Expand All @@ -630,7 +630,7 @@ BulletCollisionDetector::createBulletCollisionShape(

auto bulletCollisionShape = createBulletCollisionShapeFromAssimpMesh(mesh);

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(bulletCollisionShape));
}
else if (shape->is<HeightmapShapef>())
Expand All @@ -650,8 +650,8 @@ BulletCollisionDetector::createBulletCollisionShape(
<< shape->getType() << "]). Creating a sphere with 0.1 radius "
<< "instead.\n";

return common::make_unique<BulletCollisionShape>(
common::make_unique<btSphereShape>(0.1));
return std::make_unique<BulletCollisionShape>(
std::make_unique<btSphereShape>(0.1));

// take this back in as soon as bullet supports double in heightmaps
// const auto heightMap = static_cast<const HeightmapShaped*>(shape.get());
Expand All @@ -664,8 +664,8 @@ BulletCollisionDetector::createBulletCollisionShape(
<< shape->getType() << "] Creating a sphere with 0.1 radius "
<< "instead.\n";

return common::make_unique<BulletCollisionShape>(
common::make_unique<btSphereShape>(0.1));
return std::make_unique<BulletCollisionShape>(
std::make_unique<btSphereShape>(0.1));
}
}

Expand Down Expand Up @@ -1037,7 +1037,7 @@ std::unique_ptr<btCollisionShape> createBulletEllipsoidMesh(
triMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
}

auto gimpactMeshShape = common::make_unique<btGImpactMeshShape>(triMesh);
auto gimpactMeshShape = std::make_unique<btGImpactMeshShape>(triMesh);
gimpactMeshShape->updateBound();

return std::move(gimpactMeshShape);
Expand Down Expand Up @@ -1066,7 +1066,7 @@ std::unique_ptr<btCollisionShape> createBulletCollisionShapeFromAssimpScene(
}
}

auto gimpactMeshShape = common::make_unique<btGImpactMeshShape>(triMesh);
auto gimpactMeshShape = std::make_unique<btGImpactMeshShape>(triMesh);
gimpactMeshShape->updateBound();
gimpactMeshShape->setUserPointer(triMesh);

Expand All @@ -1090,7 +1090,7 @@ std::unique_ptr<btCollisionShape> createBulletCollisionShapeFromAssimpMesh(
triMesh->addTriangle(vertices[0], vertices[1], vertices[2]);
}

auto gimpactMeshShape = common::make_unique<btGImpactMeshShape>(triMesh);
auto gimpactMeshShape = std::make_unique<btGImpactMeshShape>(triMesh);
gimpactMeshShape->updateBound();

return std::move(gimpactMeshShape);
Expand Down Expand Up @@ -1125,7 +1125,7 @@ createBulletCollisionShapeFromHeightmap(
// create the height field
const btVector3 localScaling(scale.x(), scale.y(), scale.z());
const bool flipQuadEdges = false;
auto heightFieldShape = common::make_unique<btHeightfieldTerrainShape>(
auto heightFieldShape = std::make_unique<btHeightfieldTerrainShape>(
heightMap->getWidth(), // Width of height field
heightMap->getDepth(), // Depth of height field
heights.data(), // Height values
Expand Down Expand Up @@ -1155,7 +1155,7 @@ createBulletCollisionShapeFromHeightmap(
<< max.x() << ", " << max.y() << ", " << max.z() << "}"
<< " (will be translated by z=" << trans.z() << ")" << std::endl;

return common::make_unique<BulletCollisionShape>(
return std::make_unique<BulletCollisionShape>(
std::move(heightFieldShape), relativeShapeTransform);
}

Expand Down
2 changes: 1 addition & 1 deletion dart/collision/dart/DARTCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const std::string& DARTCollisionDetector::getStaticType()
std::unique_ptr<CollisionGroup>
DARTCollisionDetector::createCollisionGroup()
{
return common::make_unique<DARTCollisionGroup>(shared_from_this());
return std::make_unique<DARTCollisionGroup>(shared_from_this());
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion dart/collision/fcl/FCLCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ const std::string& FCLCollisionDetector::getStaticType()
std::unique_ptr<CollisionGroup>
FCLCollisionDetector::createCollisionGroup()
{
return common::make_unique<FCLCollisionGroup>(shared_from_this());
return std::make_unique<FCLCollisionGroup>(shared_from_this());
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion dart/collision/ode/OdeCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const std::string& OdeCollisionDetector::getStaticType()
//==============================================================================
std::unique_ptr<CollisionGroup> OdeCollisionDetector::createCollisionGroup()
{
return common::make_unique<OdeCollisionGroup>(shared_from_this());
return std::make_unique<OdeCollisionGroup>(shared_from_this());
}

//==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion dart/common/AspectWithVersion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class AspectWithStateAndVersionedProperties :
// Documentation inherited
std::unique_ptr<Aspect> cloneAspect() const override
{
return make_unique<Derived>(this->getState(), this->getProperties());
return std::make_unique<Derived>(this->getState(), this->getProperties());
}

};
Expand Down
2 changes: 1 addition & 1 deletion dart/common/EmbeddedAspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class EmbeddedStateAndPropertiesAspect :
// Documentation inherited
std::unique_ptr<Aspect> cloneAspect() const override
{
return make_unique<Derived>(this->getState(), this->getProperties());
return std::make_unique<Derived>(this->getState(), this->getProperties());
}

};
Expand Down
6 changes: 4 additions & 2 deletions dart/common/Memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ namespace common {
template <typename _Tp, typename... _Args>
std::shared_ptr<_Tp> make_aligned_shared(_Args&&... __args);

/// \deprecated Deprecated in 6.9. Use std::make_unique instead.
template<typename T, typename... Args>
DART_DEPRECATED(6.9)
std::unique_ptr<T> make_unique(Args&&... args);

#if EIGEN_VERSION_AT_LEAST(3,2,1) && EIGEN_VERSION_AT_MOST(3,2,8)
Expand Down Expand Up @@ -172,7 +174,7 @@ public: \
class_name, \
DART_UNIQUE_PTR_CREATOR_NAME, \
std::unique_ptr, \
::dart::common::make_unique)
::std::make_unique)

// Define static creator function that returns std::unique_ptr to the object
// where the constructor is protected
Expand All @@ -182,7 +184,7 @@ public: \
class_name, \
DART_UNIQUE_PTR_CREATOR_NAME, \
std::unique_ptr, \
::dart::common::make_unique)
::std::make_unique)

// Define two static creator functions that returns std::unique_ptr and
// std::unique_ptr, respectively, to the object
Expand Down
2 changes: 1 addition & 1 deletion dart/common/ProxyAspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ProxyStateAndPropertiesAspect :
// Documentation inherited
std::unique_ptr<Aspect> cloneAspect() const override
{
return make_unique<ProxyStateAndPropertiesAspect>();
return std::make_unique<ProxyStateAndPropertiesAspect>();
}

};
Expand Down
4 changes: 2 additions & 2 deletions dart/common/detail/AspectWithVersion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ std::unique_ptr<Aspect>
AspectWithState<BaseT, DerivedT, StateData, CompositeT, updateState>::
cloneAspect() const
{
return common::make_unique<Derived>(mState);
return std::make_unique<Derived>(mState);
}

//==============================================================================
Expand Down Expand Up @@ -312,7 +312,7 @@ AspectWithVersionedProperties<BaseT, DerivedT, PropertiesData,
CompositeT, updateProperties>::
cloneAspect() const
{
return common::make_unique<Derived>(mProperties);
return std::make_unique<Derived>(mProperties);
}

//==============================================================================
Expand Down
14 changes: 7 additions & 7 deletions dart/common/detail/Cloneable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ MakeCloneable<Base, Mixin>& MakeCloneable<Base, Mixin>::operator=(
template <class Base, class Mixin>
std::unique_ptr<Base> MakeCloneable<Base, Mixin>::clone() const
{
return common::make_unique<MakeCloneable<Base, Mixin>>(*this);
return std::make_unique<MakeCloneable<Base, Mixin>>(*this);
}

//==============================================================================
Expand All @@ -142,7 +142,7 @@ template <class Base, class OwnerT, class DataT,
DataT (*getData)(const OwnerT*)>
ProxyCloneable<Base, OwnerT, DataT, setData, getData>::ProxyCloneable()
: mOwner(nullptr),
mData(make_unique<Data>())
mData(std::make_unique<Data>())
{
// Do nothing
}
Expand Down Expand Up @@ -178,7 +178,7 @@ template <typename... Args>
ProxyCloneable<Base, OwnerT, DataT, setData, getData>::ProxyCloneable(
Args&&... args)
: mOwner(nullptr),
mData(dart::common::make_unique<Data>(std::forward<Args>(args)...))
mData(std::make_unique<Data>(std::forward<Args>(args)...))
{
// Do nothing
}
Expand Down Expand Up @@ -265,7 +265,7 @@ void ProxyCloneable<Base, OwnerT, DataT, setData, getData>::set(
return;
}

mData = make_unique<Data>(data);
mData = std::make_unique<Data>(data);
}

//==============================================================================
Expand All @@ -281,7 +281,7 @@ void ProxyCloneable<Base, OwnerT, DataT, setData, getData>::set(
return;
}

mData = dart::common::make_unique<Data>(std::move(data));
mData = std::make_unique<Data>(std::move(data));
}

//==============================================================================
Expand Down Expand Up @@ -341,7 +341,7 @@ template <class Base, class OwnerT, class DataT,
std::unique_ptr<Base> ProxyCloneable<
Base, OwnerT, DataT, setData, getData>::clone() const
{
return dart::common::make_unique<ProxyCloneable>(get());
return std::make_unique<ProxyCloneable>(get());
}

//==============================================================================
Expand Down Expand Up @@ -566,7 +566,7 @@ std::unique_ptr< CloneableVector<T> > CloneableVector<T>::clone() const
for(const T& entry : mVector)
clonedVector.push_back(entry->clone());

return common::make_unique< CloneableVector<T> >( std::move(clonedVector) );
return std::make_unique< CloneableVector<T> >( std::move(clonedVector) );
}

//==============================================================================
Expand Down
4 changes: 2 additions & 2 deletions dart/common/detail/CompositeData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CompositeData : public CloneableMap<MapType>
using DataType = typename GetData<Aspect>::Type;

std::unique_ptr<DataType>& data = this->mMap[typeid(AspectType)]
= make_unique<Data>(std::forward<Args>(args)...);
= std::make_unique<Data>(std::forward<Args>(args)...);
return static_cast<Data&>(*data);
}

Expand Down Expand Up @@ -158,7 +158,7 @@ class CompositeData : public CloneableMap<MapType>

const bool exists = !it.second;
if(!exists)
it.first = make_unique<Data>(std::forward<Args>(args)...);
it.first = std::make_unique<Data>(std::forward<Args>(args)...);

return static_cast<Data&>(*it.first);
}
Expand Down
Loading

0 comments on commit 968013c

Please sign in to comment.