Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@

#include <sofa/component/statecontainer/config.h>

namespace sofa::core
{
class ObjectFactory;
}

namespace sofa::component::statecontainer
{
SOFA_COMPONENT_STATECONTAINER_API void init();
Expand Down
5 changes: 4 additions & 1 deletion Sofa/framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ set(HEADER_FILES
${SRC_ROOT}/CategoryLibrary.h
${SRC_ROOT}/CollisionElement.h
${SRC_ROOT}/CollisionModel.h
${SRC_ROOT}/ComponentCreator.h
${SRC_ROOT}/ComponentFactory.h
${SRC_ROOT}/ComponentLibrary.h
${SRC_ROOT}/ComponentNameHelper.h
${SRC_ROOT}/ComponentRegistrationData.h
${SRC_ROOT}/ConstraintOrder.h
${SRC_ROOT}/ConstraintParams.h
${SRC_ROOT}/DataEngine.h
Expand Down Expand Up @@ -232,6 +235,7 @@ set(SOURCE_FILES
${SRC_ROOT}/BehaviorModel.cpp
${SRC_ROOT}/CategoryLibrary.cpp
${SRC_ROOT}/CollisionModel.cpp
${SRC_ROOT}/ComponentFactory.cpp
${SRC_ROOT}/ComponentLibrary.cpp
${SRC_ROOT}/ComponentNameHelper.cpp
${SRC_ROOT}/ConstraintParams.cpp
Expand All @@ -248,7 +252,6 @@ set(SOURCE_FILES
${SRC_ROOT}/MechanicalParams.cpp
${SRC_ROOT}/Multi2Mapping.cpp
${SRC_ROOT}/MultiMapping.cpp
${SRC_ROOT}/ObjectFactory.cpp
${SRC_ROOT}/ObjectFactoryJson.cpp
${SRC_ROOT}/PathResolver.cpp
${SRC_ROOT}/SofaLibrary.cpp
Expand Down
468 changes: 234 additions & 234 deletions Sofa/framework/Core/src/sofa/core/CategoryLibrary.cpp

Large diffs are not rendered by default.

166 changes: 83 additions & 83 deletions Sofa/framework/Core/src/sofa/core/CategoryLibrary.h
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
58 changes: 58 additions & 0 deletions Sofa/framework/Core/src/sofa/core/ComponentCreator.h
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();

@damienmarchal damienmarchal Jun 22, 2026

Copy link
Copy Markdown
Contributor

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.

}

std::unique_ptr<BaseComponentCreator> clone() const override
{
return std::make_unique<ComponentCreator>();
}
};

}
Loading
Loading