SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
LeastSquareEngineManager.cpp
Go to the documentation of this file.
1
22
23#include <ElementsKernel/Exception.h>
24#include <boost/algorithm/string.hpp>
26
27namespace 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
35
36
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
46 for (auto &e : getEngineFactories()) {
47 keys.emplace_back(e.first);
48 }
49 return keys;
50}
51
54 std::string default_engine;
55
56 if (std::find(known_engines.begin(), known_engines.end(), "levmar") != known_engines.end()) {
57 return "levmar";
58 }
59 else if (!known_engines.empty()) {
60 return known_engines.front();
61 }
62 return "";
63}
64
66 auto factory = getEngineFactories().find(boost::algorithm::to_lower_copy(name));
67 if (factory == getEngineFactories().end()) {
68 std::ostringstream known_str;
69 if (!getEngineFactories().empty()) {
70 known_str << ". Known engines: ";
71 for (auto &e : getEngineFactories()) {
72 known_str << e.first << " ";
73 }
74 }
75 throw Elements::Exception() << "No LeastSquareEngine named " << name << " has been registered" << known_str.str();
76 }
77 return factory->second(max_iterations);
78}
79
80} // end namespace ModelFitting
static std::shared_ptr< LeastSquareEngine > create(const std::string &name, unsigned max_iterations=1000)
static void registerEngine(const std::string &name, FactoryMethod factory_method)
std::function< std::shared_ptr< LeastSquareEngine >(unsigned)> FactoryMethod
static std::vector< std::string > getImplementations()
T emplace_back(T... args)
T end(T... args)
T find(T... args)
static std::map< std::string, LeastSquareEngineManager::FactoryMethod > & getEngineFactories()
T str(T... args)