SourceXtractorPlusPlus  0.15
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
ModelFitting::LeastSquareEngineManager::getDefault
static std::string getDefault()
Definition: LeastSquareEngineManager.cpp:52
ModelFitting::LeastSquareEngineManager::create
static std::shared_ptr< LeastSquareEngine > create(const std::string &name, unsigned max_iterations=1000)
Definition: LeastSquareEngineManager.cpp:65
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
std::string::front
T front(T... args)
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