-
Notifications
You must be signed in to change notification settings - Fork 358
Start refactoring of ObjectFactory #6162
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
Draft
alxbilger
wants to merge
1
commit into
sofa-framework:master
Choose a base branch
from
alxbilger:refactorobjectfactory
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
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 hidden or 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 hidden or 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
468 changes: 234 additions & 234 deletions
468
Sofa/framework/Core/src/sofa/core/CategoryLibrary.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,83 +1,83 @@ | ||
| /****************************************************************************** | ||
| * 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: contact@sofa-framework.org * | ||
| ******************************************************************************/ | ||
| #pragma once | ||
|
|
||
| #include <sofa/core/ComponentLibrary.h> | ||
|
|
||
| namespace sofa::core | ||
| { | ||
|
|
||
|
|
||
| using Creator = sofa::core::ObjectFactory::BaseObjectCreator; | ||
|
|
||
| /** | ||
| * \brief An Generic Category of the Sofa Library | ||
| * | ||
| * It contains all the components available for Sofa corresponding to a given category (force field, mass, mapping...) | ||
| * This Interface is used for the Modeler mainly. | ||
| * | ||
| */ | ||
| class SOFA_CORE_API CategoryLibrary | ||
| { | ||
| public: | ||
| typedef std::vector< ComponentLibrary* > VecComponent; | ||
| typedef VecComponent::const_iterator VecComponentIterator; | ||
|
|
||
| CategoryLibrary( const std::string &categoryName); | ||
| virtual ~CategoryLibrary() {} | ||
|
|
||
| virtual ComponentLibrary *addComponent(const std::string &componentName, ClassEntry::SPtr entry, const std::vector< std::string > &exampleFiles); | ||
| virtual void endConstruction(); | ||
|
|
||
| const std::string &getName() const { return name;} | ||
| const VecComponent &getComponents() const {return components;} | ||
|
|
||
| const ComponentLibrary *getComponent( const std::string &componentName) const; | ||
|
|
||
| size_t getNumComponents() const {return components.size();} | ||
|
|
||
| /** \brief Get the list of categories a class belongs to, based on its parent classes. | ||
| * | ||
| * @param mclass the class the categorize | ||
| * @param outputVector the vector where to push the categories | ||
| * | ||
| * The categories are: AnimationLoop, BehaviorModel, | ||
| * CollisionAlgorithm, CollisionAlgorithm, CollisionAlgorithm, | ||
| * CollisionModel, ConfigurationSetting, ConstraintSet, | ||
| * ConstraintSolver, ConstraintSolver, ContextObject, Controller, | ||
| * Engine, Exporter, ForceField, InteractionForceField, LinearSolver, LinearSystem, | ||
| * Loader, Mapping, Mass, MechanicalState, OdeSolver, OrderingMethod, | ||
| * ProjectiveConstraintSet, TopologicalMapping, Topology, | ||
| * TopologyObject, and VisualModel | ||
| */ | ||
| static void getCategories(const sofa::core::objectmodel::BaseClass* mclass, | ||
| std::vector<std::string>& outputVector); | ||
| static std::vector<std::string> getCategories(); | ||
|
|
||
| protected: | ||
| virtual ComponentLibrary *createComponent(const std::string &componentName, ClassEntry::SPtr entry, const std::vector< std::string > &exampleFiles) {return new ComponentLibrary(componentName, name, entry, exampleFiles);} | ||
|
|
||
| std::string name; | ||
| VecComponent components; | ||
| }; | ||
|
|
||
| } // namespace sofa::core | ||
| // /****************************************************************************** | ||
| // * 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: contact@sofa-framework.org * | ||
| // ******************************************************************************/ | ||
| // #pragma once | ||
| // | ||
| // #include <sofa/core/ComponentLibrary.h> | ||
| // | ||
| // namespace sofa::core | ||
| // { | ||
| // | ||
| // | ||
| // using Creator = sofa::core::ObjectFactory::BaseObjectCreator; | ||
| // | ||
| // /** | ||
| // * \brief An Generic Category of the Sofa Library | ||
| // * | ||
| // * It contains all the components available for Sofa corresponding to a given category (force field, mass, mapping...) | ||
| // * This Interface is used for the Modeler mainly. | ||
| // * | ||
| // */ | ||
| // class SOFA_CORE_API CategoryLibrary | ||
| // { | ||
| // public: | ||
| // typedef std::vector< ComponentLibrary* > VecComponent; | ||
| // typedef VecComponent::const_iterator VecComponentIterator; | ||
| // | ||
| // CategoryLibrary( const std::string &categoryName); | ||
| // virtual ~CategoryLibrary() {} | ||
| // | ||
| // virtual ComponentLibrary *addComponent(const std::string &componentName, ClassEntry::SPtr entry, const std::vector< std::string > &exampleFiles); | ||
| // virtual void endConstruction(); | ||
| // | ||
| // const std::string &getName() const { return name;} | ||
| // const VecComponent &getComponents() const {return components;} | ||
| // | ||
| // const ComponentLibrary *getComponent( const std::string &componentName) const; | ||
| // | ||
| // size_t getNumComponents() const {return components.size();} | ||
| // | ||
| // /** \brief Get the list of categories a class belongs to, based on its parent classes. | ||
| // * | ||
| // * @param mclass the class the categorize | ||
| // * @param outputVector the vector where to push the categories | ||
| // * | ||
| // * The categories are: AnimationLoop, BehaviorModel, | ||
| // * CollisionAlgorithm, CollisionAlgorithm, CollisionAlgorithm, | ||
| // * CollisionModel, ConfigurationSetting, ConstraintSet, | ||
| // * ConstraintSolver, ConstraintSolver, ContextObject, Controller, | ||
| // * Engine, Exporter, ForceField, InteractionForceField, LinearSolver, LinearSystem, | ||
| // * Loader, Mapping, Mass, MechanicalState, OdeSolver, OrderingMethod, | ||
| // * ProjectiveConstraintSet, TopologicalMapping, Topology, | ||
| // * TopologyObject, and VisualModel | ||
| // */ | ||
| // static void getCategories(const sofa::core::objectmodel::BaseClass* mclass, | ||
| // std::vector<std::string>& outputVector); | ||
| // static std::vector<std::string> getCategories(); | ||
| // | ||
| // protected: | ||
| // virtual ComponentLibrary *createComponent(const std::string &componentName, ClassEntry::SPtr entry, const std::vector< std::string > &exampleFiles) {return new ComponentLibrary(componentName, name, entry, exampleFiles);} | ||
| // | ||
| // std::string name; | ||
| // VecComponent components; | ||
| // }; | ||
| // | ||
| // } // namespace sofa::core |
This file contains hidden or 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,58 @@ | ||
| /****************************************************************************** | ||
| * 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: contact@sofa-framework.org * | ||
| ******************************************************************************/ | ||
| #pragma once | ||
|
|
||
| #include <sofa/core/config.h> | ||
|
|
||
| #include <sofa/core/objectmodel/BaseComponent.h> | ||
|
|
||
| namespace sofa::core | ||
| { | ||
|
|
||
| struct SOFA_CORE_API BaseComponentCreator | ||
| { | ||
| virtual ~BaseComponentCreator() = default; | ||
| virtual objectmodel::BaseComponent::SPtr create() const = 0; | ||
| virtual const objectmodel::BaseClass* getClass() = 0; | ||
| virtual std::unique_ptr<BaseComponentCreator> clone() const = 0; | ||
| }; | ||
|
|
||
| template<class RealComponent> | ||
| struct ComponentCreator : public BaseComponentCreator | ||
| { | ||
| objectmodel::BaseComponent::SPtr create() const override | ||
| { | ||
| return sofa::core::objectmodel::New<RealComponent>(); | ||
| } | ||
|
|
||
| const objectmodel::BaseClass* getClass() override | ||
| { | ||
| return RealComponent::GetClass(); | ||
| } | ||
|
|
||
| std::unique_ptr<BaseComponentCreator> clone() const override | ||
| { | ||
| return std::make_unique<ComponentCreator>(); | ||
| } | ||
| }; | ||
|
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
If we are refactoring component factory could we drop this please.
If I remenber correctly this single line is causing a compilation code bloat (just to provide the class name). When we are registering a component into the factory the class name could be passed with a std::string instead of relying a complex custom "reflection" system.