Skip to content

Commit e629d03

Browse files
committed
Apply new factory registration mechanism
1 parent e48aab6 commit e629d03

4 files changed

Lines changed: 36 additions & 18 deletions

File tree

src/CSparseSolvers/SparseCholeskySolver.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ using namespace sofa::linearalgebra;
3131
#ifdef SOFA_FLOAT
3232
SOFA_PRAGMA_WARNING("SparseCholeskySolver does not support float as scalar.")
3333
#else // SOFA_DOUBLE
34-
int SparseCholeskySolverClass =
35-
sofa::core::RegisterObject(
36-
"Direct linear solver based on Sparse Cholesky factorization, implemented with the "
37-
"CSPARSE library")
38-
.add<SparseCholeskySolver<CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >();
3934

40-
template class SOFA_CSPARSESOLVERS_API
41-
SparseCholeskySolver<CompressedRowSparseMatrix<SReal>, FullVector<SReal> >;
35+
void registerSparseCholeskySolver(sofa::core::ObjectFactory* factory)
36+
{
37+
factory->registerObjects(sofa::core::ObjectRegistrationData("Direct linear solver based on Sparse Cholesky factorization, implemented with the CSPARSE library")
38+
.add<SparseCholeskySolver<CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >());
39+
}
40+
41+
template class SOFA_CSPARSESOLVERS_API SparseCholeskySolver<CompressedRowSparseMatrix<SReal>, FullVector<SReal> >;
4242
#endif // SOFA_FLOAT
4343

4444
} // namespace sofa::component::linearsolver::direct

src/CSparseSolvers/SparseLUSolver.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ using namespace sofa::linearalgebra;
3333
#ifdef SOFA_FLOAT
3434
SOFA_PRAGMA_WARNING("SparseLUSolver does not support float as scalar.")
3535
#else // SOFA_DOUBLE
36-
int SparseLUSolverClass = sofa::core::RegisterObject("Direct linear solver based on Sparse LU factorization, implemented with the CSPARSE library")
37-
.add< SparseLUSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
38-
.add< SparseLUSolver< CompressedRowSparseMatrix<sofa::type::Mat<3,3,SReal> >,FullVector<SReal> > >()
39-
;
36+
37+
void registerSparseLUSolver(sofa::core::ObjectFactory* factory)
38+
{
39+
factory->registerObjects(sofa::core::ObjectRegistrationData("Direct linear solver based on Sparse LU factorization, implemented with the CSPARSE library")
40+
.add< SparseLUSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> > >()
41+
.add< SparseLUSolver< CompressedRowSparseMatrix<sofa::type::Mat<3,3,SReal> >,FullVector<SReal> > >());
42+
}
4043

4144
template class SOFA_CSPARSESOLVERS_API SparseLUSolver< CompressedRowSparseMatrix<SReal>, FullVector<SReal> >;
4245
template class SOFA_CSPARSESOLVERS_API SparseLUSolver< CompressedRowSparseMatrix<sofa::type::Mat<3,3,SReal> >, FullVector<SReal> >;

src/CSparseSolvers/config.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
#else
1111
# define SOFA_CSPARSESOLVERS_API SOFA_IMPORT_DYNAMIC_LIBRARY
1212
#endif
13+
14+
namespace csparsesolvers
15+
{
16+
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
17+
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
18+
} // namespace csparsesolvers

src/CSparseSolvers/init.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,43 @@
22

33
#include <sofa/core/ObjectFactory.h>
44
using sofa::core::ObjectFactory;
5+
#include <sofa/helper/system/PluginManager.h>
6+
7+
namespace csparsesolvers
8+
{
9+
extern void registerSparseLUSolver(sofa::core::ObjectFactory* factory);
10+
extern void registerSparseCholeskySolver(sofa::core::ObjectFactory* factory);
11+
}
512

613
extern "C" {
714
SOFA_CSPARSESOLVERS_API void initExternalModule();
815
SOFA_CSPARSESOLVERS_API const char* getModuleName();
916
SOFA_CSPARSESOLVERS_API const char* getModuleVersion();
1017
SOFA_CSPARSESOLVERS_API const char* getModuleLicense();
1118
SOFA_CSPARSESOLVERS_API const char* getModuleDescription();
12-
SOFA_CSPARSESOLVERS_API const char* getModuleComponentList();
19+
SOFA_CSPARSESOLVERS_API void registerObjects(sofa::core::ObjectFactory* factory);
1320
}
1421

1522
void initExternalModule()
1623
{
1724
static bool first = true;
1825
if (first)
1926
{
27+
// make sure that this plugin is registered into the PluginManager
28+
sofa::helper::system::PluginManager::getInstance().registerPlugin(csparsesolvers::MODULE_NAME);
29+
2030
first = false;
2131
}
2232
}
2333

2434
const char* getModuleName()
2535
{
26-
return sofa_tostring(SOFA_TARGET);
36+
return csparsesolvers::MODULE_NAME;
2737
}
2838

2939
const char* getModuleVersion()
3040
{
31-
return sofa_tostring(CSPARSESOLVERS_VERSION);
41+
return csparsesolvers::MODULE_VERSION;
3242
}
3343

3444
const char* getModuleLicense()
@@ -41,9 +51,8 @@ const char* getModuleDescription()
4151
return "A set of linear solvers based on the library CSparse";
4252
}
4353

44-
const char* getModuleComponentList()
54+
void registerObjects(sofa::core::ObjectFactory* factory)
4555
{
46-
/// string containing the names of the classes provided by the plugin
47-
static std::string classes = ObjectFactory::getInstance()->listClassesFromTarget(sofa_tostring(SOFA_TARGET));
48-
return classes.c_str();
56+
csparsesolvers::registerSparseLUSolver(factory);
57+
csparsesolvers::registerSparseCholeskySolver(factory);
4958
}

0 commit comments

Comments
 (0)