-
Notifications
You must be signed in to change notification settings - Fork 312
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
[Core] Modern visitor creation #5126
Draft
alxbilger
wants to merge
8
commits into
sofa-framework:master
Choose a base branch
from
alxbilger:newvisitors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
363d706
[Core] Modern visitor creation
alxbilger 6c2ea48
examples
alxbilger c6c528e
consistency order with BaseMechanicalVisitor
alxbilger afee53f
fix test
alxbilger 0fc0eca
default behavior for interaction components is to call the function o…
alxbilger 8abbb70
remove unused variable warning
alxbilger cda3269
forgot the condition on diagonal masses
alxbilger 7b8af41
modern visitor creation (the old ones)
alxbilger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Sofa/framework/Core/src/sofa/core/objectmodel/VisitorDirection.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/****************************************************************************** | ||
* SOFA, Simulation Open-Framework Architecture * | ||
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify it * | ||
* under the terms of the GNU Lesser General Public License as published by * | ||
* the Free Software Foundation; either version 2.1 of the License, or (at * | ||
* your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, but WITHOUT * | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * | ||
* for more details. * | ||
* * | ||
* You should have received a copy of the GNU Lesser General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
******************************************************************************* | ||
* Authors: The SOFA Team and external contributors (see Authors.txt) * | ||
* * | ||
* Contact information: [email protected] * | ||
******************************************************************************/ | ||
#pragma once | ||
#include <sofa/core/config.h> | ||
|
||
namespace sofa::core::objectmodel | ||
{ | ||
|
||
struct DirectionalVisitor | ||
{ | ||
virtual ~DirectionalVisitor() = default; | ||
DirectionalVisitor() = default; | ||
virtual void operator()(sofa::core::behavior::OdeSolver*) const {} | ||
virtual void operator()(sofa::core::behavior::ConstraintSolver*) const {} | ||
virtual void operator()(sofa::core::BaseMapping*) const {} | ||
virtual void operator()(sofa::core::behavior::BaseMechanicalState*) const {} | ||
virtual void operator()(sofa::core::behavior::BaseMass*) const {} | ||
virtual void operator()(sofa::core::behavior::BaseForceField*) const {} | ||
virtual void operator()(sofa::core::behavior::BaseInteractionForceField* force) const | ||
{ | ||
this->operator()((behavior::BaseForceField*)force); | ||
} | ||
virtual void operator()(sofa::core::behavior::BaseProjectiveConstraintSet*) const {} | ||
virtual void operator()(sofa::core::behavior::BaseConstraintSet*) const {} | ||
virtual void operator()(sofa::core::behavior::BaseInteractionProjectiveConstraintSet* constraint) const | ||
{ | ||
this->operator()((behavior::BaseProjectiveConstraintSet*)constraint); | ||
} | ||
virtual void operator()(sofa::core::behavior::BaseInteractionConstraint* constraint) const | ||
{ | ||
this->operator()((behavior::BaseConstraintSet*)constraint); | ||
} | ||
}; | ||
|
||
struct SOFA_CORE_API TopDownVisitor : DirectionalVisitor | ||
{ | ||
TopDownVisitor() = default; | ||
}; | ||
struct SOFA_CORE_API BottomUpVisitor : DirectionalVisitor | ||
{ | ||
BottomUpVisitor() = default; | ||
}; | ||
|
||
inline TopDownVisitor topDownVisitor {}; | ||
inline BottomUpVisitor bottomUpVisitor {}; | ||
|
||
|
||
template<class VisitorDirection, class Func, class VisitedObject, | ||
typename = std::enable_if_t<std::is_invocable_v<Func, VisitedObject*>>> | ||
struct SpecializedVisitor : public virtual VisitorDirection | ||
{ | ||
Func m_specializedFunction; | ||
|
||
SpecializedVisitor(const VisitorDirection& visitor, const Func& specializedFunction) | ||
: VisitorDirection(visitor), m_specializedFunction(specializedFunction) {} | ||
|
||
void operator()(VisitedObject* object) const override | ||
{ | ||
m_specializedFunction(object); | ||
} | ||
}; | ||
|
||
#define DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(ObjectType) \ | ||
template<class VisitorDirection, class Func, \ | ||
typename = std::enable_if_t<std::is_invocable_v<Func, ObjectType*>>> \ | ||
SpecializedVisitor<VisitorDirection, Func, ObjectType> operator|( \ | ||
const VisitorDirection& input, \ | ||
const Func& f) \ | ||
{ \ | ||
return {input, f}; \ | ||
} | ||
|
||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::OdeSolver) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::ConstraintSolver) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::BaseMapping) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseMechanicalState) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseMass) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseForceField) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseInteractionForceField) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseProjectiveConstraintSet) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseConstraintSet) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseInteractionProjectiveConstraintSet) | ||
DEFINE_PIPE_OPERATOR_FOR_OBJECT_TYPE(sofa::core::behavior::BaseInteractionConstraint) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the same name with only no capital letter at the beginning is misleading. Given the fact that this is kind of equivalent to a static object, why not add a suffix ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no guidelines in SOFA relative to the naming of global variables (I already saw a convention with a
g_
prefix). But I agree with you the names of the type and the variable are too similar. The STL has the same design for execution policy, and the variable names are truncated to differentiate with the type names. But here, I don't like it so much. Let's discuss that in the dev meeting.Keep in mind that this is a detail of one of the implementation of the visitors. We still need to decide which one of both implementations we keep. That's the main question of this PR.