SourceXtractorPlusPlus
0.10
Please provide a description of the project.
ModelFitting
src
lib
Engine
LeastSquareEngineManager.cpp
Go to the documentation of this file.
1
23
#include <
ElementsKernel/Exception.h
>
24
#include <boost/algorithm/string.hpp>
25
#include "
ModelFitting/Engine/LeastSquareEngineManager.h
"
26
27
namespace
ModelFitting
{
28
29
// We use this idiom to make sure the map is initialized on the first need
30
// Otherwise, this may be initialized *after* the concrete implementations try to register themselves
31
static
std::map<std::string, LeastSquareEngineManager::FactoryMethod>
&
getEngineFactories
() {
32
static
std::map<std::string, LeastSquareEngineManager::FactoryMethod>
engine_factories;
33
return
engine_factories;
34
}
35
36
37
void
LeastSquareEngineManager::registerEngine
(
const
std::string
& name,
FactoryMethod
factory_method) {
38
if
(
getEngineFactories
().
find
(name) !=
getEngineFactories
().
end
()) {
39
throw
Elements::Exception
() <<
"A LeastSquareEngine named "
<< name <<
" has already been registered"
;
40
}
41
getEngineFactories
()[boost::algorithm::to_lower_copy(name)] = factory_method;
42
}
43
44
std::vector<std::string>
LeastSquareEngineManager::getImplementations
() {
45
std::vector<std::string>
keys;
46
for
(
auto
&
e
:
getEngineFactories
()) {
47
keys.
emplace_back
(
e
.first);
48
}
49
return
keys;
50
}
51
52
std::shared_ptr<LeastSquareEngine>
LeastSquareEngineManager::create
(
const
std::string
& name,
unsigned
max_iterations) {
53
auto
factory =
getEngineFactories
().find(boost::algorithm::to_lower_copy(name));
54
if
(factory ==
getEngineFactories
().
end
()) {
55
std::ostringstream
known_str;
56
if
(!
getEngineFactories
().empty()) {
57
known_str <<
". Known engines: "
;
58
for
(
auto
&
e
:
getEngineFactories
()) {
59
known_str <<
e
.first <<
" "
;
60
}
61
}
62
throw
Elements::Exception
() <<
"No LeastSquareEngine named "
<< name <<
" has been registered"
<< known_str.
str
();
63
}
64
return
factory->second(max_iterations);
65
}
66
67
}
// end namespace ModelFitting
ModelFitting::LeastSquareEngineManager::create
static std::shared_ptr< LeastSquareEngine > create(const std::string &name, unsigned max_iterations=1000)
Definition:
LeastSquareEngineManager.cpp:52
std::string
STL class.
std::shared_ptr
STL class.
std::vector< std::string >
std::find
T find(T... args)
ModelFitting::getEngineFactories
static std::map< std::string, LeastSquareEngineManager::FactoryMethod > & getEngineFactories()
Definition:
LeastSquareEngineManager.cpp:31
std::function
Exception.h
LeastSquareEngineManager.h
Elements::Exception
std::map
STL class.
e
constexpr double e
std::ostringstream
STL class.
std::vector::emplace_back
T emplace_back(T... args)
ModelFitting::LeastSquareEngineManager::getImplementations
static std::vector< std::string > getImplementations()
Definition:
LeastSquareEngineManager.cpp:44
std::ostringstream::str
T str(T... args)
std::end
T end(T... args)
ModelFitting
Definition:
AsinhChiSquareComparator.h:30
ModelFitting::LeastSquareEngineManager::registerEngine
static void registerEngine(const std::string &name, FactoryMethod factory_method)
Definition:
LeastSquareEngineManager.cpp:37
Generated by
1.8.17