SourceXtractorPlusPlus  0.12
Please provide a description of the project.
LeastSquareEngineManager.cpp
Go to the documentation of this file.
1 
24 #include <boost/algorithm/string.hpp>
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
33  return engine_factories;
34 }
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
T front(T... args)
static std::map< std::string, LeastSquareEngineManager::FactoryMethod > & getEngineFactories()
constexpr double e
static std::vector< std::string > getImplementations()
T end(T... args)
static void registerEngine(const std::string &name, FactoryMethod factory_method)
STL class.
STL class.
T str(T... args)
T find(T... args)
static std::shared_ptr< LeastSquareEngine > create(const std::string &name, unsigned max_iterations=1000)
T emplace_back(T... args)