Skip to content

Commit

Permalink
[all] Compatibility with C++20 (#5056)
Browse files Browse the repository at this point in the history
* Fix std::memory_order according to changes in C++20

The new code should be compatible with C++17 as well

* declare BilateralLagrangianConstraint::bwdInit specialization

* simplify real type

* remove duplicated using

* scope initData to direct parent

* remove forward declaration

* Missing aliases cause compilation fail
  • Loading branch information
alxbilger authored Nov 14, 2024
1 parent ba947da commit 882c296
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class BilateralLagrangianConstraint : public PairInteractionConstraint<DataTypes
Index indexOfElemConstraint(const SubsetIndices& cIndices, Index Id);
};

template<> SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API
void BilateralLagrangianConstraint<Rigid3Types>::bwdInit();


#if !defined(SOFA_COMPONENT_CONSTRAINTSET_BILATERALLAGRANGIANCONSTRAINT_CPP)
extern template class SOFA_COMPONENT_CONSTRAINT_LAGRANGIAN_MODEL_API BilateralLagrangianConstraint< Vec3Types >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ConstraintProblem::clear(int nbConstraints)
f.resize(nbConstraints);

static std::atomic<unsigned int> counter = 0;
problemId = counter.fetch_add(1, std::memory_order::memory_order_relaxed);
problemId = counter.fetch_add(1, std::memory_order_relaxed);
}

unsigned int ConstraintProblem::getProblemId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace sofa::component::engine::transform
{

template <class DataTypes>
const typename Vertex2Frame<DataTypes>::Real Vertex2Frame<DataTypes>::EPSILON = std::numeric_limits<Vertex2Frame<DataTypes>::Real>::epsilon();
const Real_t<DataTypes> Vertex2Frame<DataTypes>::EPSILON = std::numeric_limits<Real_t<DataTypes>>::epsilon();

template <class DataTypes>
Vertex2Frame<DataTypes>::Vertex2Frame():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class BaseAssemblingMatrixAccumulator : public sofa::core::get_base_object_stron
SOFA_CLASS(SOFA_TEMPLATE(BaseAssemblingMatrixAccumulator, c), sofa::core::get_base_object_strong_type<c>);
using ComponentType = typename Inherit1::ComponentType;

using Inherit1::initData;
using Inherit1::add;

virtual void setMatrixSize(const sofa::type::Vec2u&);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class IdentityMapping : public LinearMapping<TIn, TOut>
typedef typename In::Coord InCoord;
typedef typename In::Deriv InDeriv;
typedef typename In::MatrixDeriv InMatrixDeriv;
typedef Data<InVecCoord> InDataVecCoord;
typedef Data<InVecDeriv> InDataVecDeriv;

typedef typename Out::VecCoord VecCoord;
typedef typename Out::VecDeriv VecDeriv;
Expand All @@ -61,6 +63,8 @@ class IdentityMapping : public LinearMapping<TIn, TOut>
typedef typename OutDataTypes::Real OutReal;
typedef typename OutDataTypes::VecCoord OutVecCoord;
typedef typename OutDataTypes::VecDeriv OutVecDeriv;
typedef Data<OutVecCoord> OutDataVecCoord;
typedef Data<OutVecDeriv> OutDataVecDeriv;

enum
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ class RigidMapping : public core::Mapping<TIn, TOut>, public NonLinearMappingDat
typedef typename Out::VecCoord OutVecCoord;
typedef typename Out::VecDeriv OutVecDeriv;
typedef typename Out::MatrixDeriv OutMatrixDeriv;
typedef Data<OutVecCoord> OutDataVecCoord;
typedef Data<OutVecDeriv> OutDataVecDeriv;

typedef typename In::Real InReal;
typedef typename In::Coord InCoord;
typedef typename In::Deriv InDeriv;
typedef typename In::VecCoord InVecCoord;
typedef typename In::VecDeriv InVecDeriv;
typedef typename In::MatrixDeriv InMatrixDeriv;
typedef Data<InVecCoord> InDataVecCoord;
typedef Data<InVecDeriv> InDataVecDeriv;

enum
{
Expand Down
13 changes: 12 additions & 1 deletion Sofa/framework/Core/src/sofa/core/objectmodel/BaseClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef T MyType; \
typedef ::sofa::core::objectmodel::TClass< T, Parent > MyClass; \
typedef Parent Inherit1; \
using Parent::initData; \
SOFA_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 1 base class
#define SOFA_ABSTRACT_CLASS(T,Parent) \
typedef T MyType; \
typedef ::sofa::core::objectmodel::TClass< T, Parent > MyClass; \
typedef Parent Inherit1; \
using Parent::initData; \
SOFA_ABSTRACT_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 2 base classes
Expand All @@ -126,6 +128,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef ::sofa::core::objectmodel::TClass< T, ::sofa::core::objectmodel::Parents<Parent1, Parent2> > MyClass; \
typedef Parent1 Inherit1; \
typedef Parent2 Inherit2; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 2 base classes
Expand All @@ -134,6 +137,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef ::sofa::core::objectmodel::TClass< T, ::sofa::core::objectmodel::Parents<Parent1, Parent2> > MyClass; \
typedef Parent1 Inherit1; \
typedef Parent2 Inherit2; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_ABSTRACT_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 3 base classes
Expand All @@ -143,6 +147,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent1 Inherit1; \
typedef Parent2 Inherit2; \
typedef Parent3 Inherit3; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 3 base classes
Expand All @@ -152,6 +157,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent1 Inherit1; \
typedef Parent2 Inherit2; \
typedef Parent3 Inherit3; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_ABSTRACT_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 4 base classes
Expand All @@ -162,6 +168,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent2 Inherit2; \
typedef Parent3 Inherit3; \
typedef Parent4 Inherit4; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 4 base classes
Expand All @@ -172,6 +179,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent2 Inherit2; \
typedef Parent3 Inherit3; \
typedef Parent4 Inherit4; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_ABSTRACT_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 5 base classes
Expand All @@ -183,6 +191,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent3 Inherit3; \
typedef Parent4 Inherit4; \
typedef Parent5 Inherit5; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 5 base classes
Expand All @@ -194,6 +203,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent3 Inherit3; \
typedef Parent4 Inherit4; \
typedef Parent5 Inherit5; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_ABSTRACT_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 5 base classes
Expand All @@ -206,6 +216,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent4 Inherit4; \
typedef Parent5 Inherit5; \
typedef Parent6 Inherit6; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_CLASS_DECL

// This macro should now be used at the beginning of all declarations of classes with 5 base classes
Expand All @@ -218,6 +229,7 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
typedef Parent4 Inherit4; \
typedef Parent5 Inherit5; \
typedef Parent6 Inherit6; \
using ::sofa::core::objectmodel::Base::initData; \
SOFA_ABSTRACT_CLASS_DECL

// Do not use this macro directly, use SOFA_ABSTRACT_CLASS instead
Expand All @@ -230,7 +242,6 @@ class SOFA_CORE_API DeprecatedBaseClass : public BaseClass
virtual const ::sofa::core::objectmodel::BaseClass* getClass() const override \
{ return GetClass(); } \
static const char* HeaderFileLocation() { return __FILE__; } \
using ::sofa::core::objectmodel::Base::initData; \
::sofa::core::objectmodel::BaseLink::InitLink<MyType> \
initLink(const char* name, const char* help) \
{ \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ void DefaultTaskScheduler::WaitForWorkersToBeReady()

void DefaultTaskScheduler::setMainTaskStatus(const Task::Status* mainTaskStatus)
{
m_mainTaskStatus.store(mainTaskStatus, std::memory_order::memory_order_relaxed);
m_mainTaskStatus.store(mainTaskStatus, std::memory_order_relaxed);
}

bool DefaultTaskScheduler::testMainTaskStatus(const Task::Status* status)
{
return m_mainTaskStatus.load(std::memory_order::memory_order_relaxed) == status;
return m_mainTaskStatus.load(std::memory_order_relaxed) == status;
}

} // namespace sofa::simulation
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@
#include <sofa/simulation/fwd.h>
#include <sofa/core/visual/VisualLoop.h>
#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/simulation/Node.h>

namespace sofa::core::objectmodel
{
// Forward declaration for extern template declaration. This design permit to
// not #include<sofa::simulation::Node>
extern template class SingleLink< sofa::simulation::DefaultVisualManagerLoop, simulation::Node, BaseLink::FLAG_STOREPATH>;
}

namespace sofa::simulation
{
Expand Down

0 comments on commit 882c296

Please sign in to comment.