g2o
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes | List of all members
g2o::OptimizationAlgorithmFactory Class Reference

create solvers based on their short name More...

#include <optimization_algorithm_factory.h>

Collaboration diagram for g2o::OptimizationAlgorithmFactory:
Collaboration graph
[legend]

Public Types

typedef std::list< AbstractOptimizationAlgorithmCreator * > CreatorList
 

Public Member Functions

void registerSolver (AbstractOptimizationAlgorithmCreator *c)
 
void unregisterSolver (AbstractOptimizationAlgorithmCreator *c)
 
OptimizationAlgorithmconstruct (const std::string &tag, OptimizationAlgorithmProperty &solverProperty) const
 
void listSolvers (std::ostream &os) const
 list the known solvers into a stream More...
 
const CreatorListcreatorList () const
 return the underlying list of creators More...
 

Static Public Member Functions

static OptimizationAlgorithmFactoryinstance ()
 return the instance More...
 
static void destroy ()
 free the instance More...
 

Protected Member Functions

 OptimizationAlgorithmFactory ()
 
 ~OptimizationAlgorithmFactory ()
 
CreatorList::const_iterator findSolver (const std::string &name) const
 
CreatorList::iterator findSolver (const std::string &name)
 

Protected Attributes

CreatorList _creator
 

Static Private Attributes

static OptimizationAlgorithmFactoryfactoryInstance = 0
 

Detailed Description

create solvers based on their short name

Factory to allocate solvers based on their short name. The Factory is implemented as a sigleton and the single instance can be accessed via the instance() function.

Definition at line 75 of file optimization_algorithm_factory.h.

Member Typedef Documentation

Definition at line 78 of file optimization_algorithm_factory.h.

Constructor & Destructor Documentation

g2o::OptimizationAlgorithmFactory::OptimizationAlgorithmFactory ( )
protected

Definition at line 44 of file optimization_algorithm_factory.cpp.

45  {
46  }
g2o::OptimizationAlgorithmFactory::~OptimizationAlgorithmFactory ( )
protected

Definition at line 48 of file optimization_algorithm_factory.cpp.

49  {
50  for (CreatorList::iterator it = _creator.begin(); it != _creator.end(); ++it)
51  delete *it;
52  }

Member Function Documentation

OptimizationAlgorithm * g2o::OptimizationAlgorithmFactory::construct ( const std::string &  tag,
OptimizationAlgorithmProperty solverProperty 
) const

construct a solver based on its name, e.g., var, fix3_2_cholmod

Definition at line 84 of file optimization_algorithm_factory.cpp.

Referenced by MainWindow::allocateSolver(), g2o::SparseOptimizerOnline::initSolver(), and main().

85  {
86  CreatorList::const_iterator foundIt = findSolver(name);
87  if (foundIt != _creator.end()) {
88  solverProperty = (*foundIt)->property();
89  return (*foundIt)->construct();
90  }
91  cerr << "SOLVER FACTORY WARNING: Unable to create solver " << name << endl;
92  return 0;
93  }
CreatorList::const_iterator findSolver(const std::string &name) const
const CreatorList& g2o::OptimizationAlgorithmFactory::creatorList ( ) const
inline

return the underlying list of creators

Definition at line 105 of file optimization_algorithm_factory.h.

void g2o::OptimizationAlgorithmFactory::destroy ( )
static

free the instance

Definition at line 95 of file optimization_algorithm_factory.cpp.

96  {
97  delete factoryInstance;
98  factoryInstance = 0;
99  }
static OptimizationAlgorithmFactory * factoryInstance
OptimizationAlgorithmFactory::CreatorList::const_iterator g2o::OptimizationAlgorithmFactory::findSolver ( const std::string &  name) const
protected

Definition at line 117 of file optimization_algorithm_factory.cpp.

References g2o::OptimizationAlgorithmProperty::name.

118  {
119  for (CreatorList::const_iterator it = _creator.begin(); it != _creator.end(); ++it) {
120  const OptimizationAlgorithmProperty& sp = (*it)->property();
121  if (sp.name == name)
122  return it;
123  }
124  return _creator.end();
125  }
OptimizationAlgorithmFactory::CreatorList::iterator g2o::OptimizationAlgorithmFactory::findSolver ( const std::string &  name)
protected

Definition at line 127 of file optimization_algorithm_factory.cpp.

References g2o::OptimizationAlgorithmProperty::name.

128  {
129  for (CreatorList::iterator it = _creator.begin(); it != _creator.end(); ++it) {
130  const OptimizationAlgorithmProperty& sp = (*it)->property();
131  if (sp.name == name)
132  return it;
133  }
134  return _creator.end();
135  }
OptimizationAlgorithmFactory * g2o::OptimizationAlgorithmFactory::instance ( )
static
void g2o::OptimizationAlgorithmFactory::listSolvers ( std::ostream &  os) const

list the known solvers into a stream

Definition at line 101 of file optimization_algorithm_factory.cpp.

References g2o::OptimizationAlgorithmProperty::desc, and g2o::OptimizationAlgorithmProperty::name.

Referenced by main().

102  {
103  size_t solverNameColumnLength = 0;
104  for (CreatorList::const_iterator it = _creator.begin(); it != _creator.end(); ++it)
105  solverNameColumnLength = std::max(solverNameColumnLength, (*it)->property().name.size());
106  solverNameColumnLength += 4;
107 
108  for (CreatorList::const_iterator it = _creator.begin(); it != _creator.end(); ++it) {
109  const OptimizationAlgorithmProperty& sp = (*it)->property();
110  os << sp.name;
111  for (size_t i = sp.name.size(); i < solverNameColumnLength; ++i)
112  os << ' ';
113  os << sp.desc << endl;
114  }
115  }
void g2o::OptimizationAlgorithmFactory::registerSolver ( AbstractOptimizationAlgorithmCreator c)

register a specific creator for allocating a solver

Definition at line 62 of file optimization_algorithm_factory.cpp.

References g2o::OptimizationAlgorithmProperty::name, and g2o::AbstractOptimizationAlgorithmCreator::property().

Referenced by g2o::RegisterOptimizationAlgorithmProxy::RegisterOptimizationAlgorithmProxy().

63  {
64  const string& name = c->property().name;
65  CreatorList::iterator foundIt = findSolver(name);
66  if (foundIt != _creator.end()) {
67  _creator.erase(foundIt);
68  cerr << "SOLVER FACTORY WARNING: Overwriting Solver creator " << name << endl;
69  assert(0);
70  }
71  _creator.push_back(c);
72  }
CreatorList::const_iterator findSolver(const std::string &name) const
void g2o::OptimizationAlgorithmFactory::unregisterSolver ( AbstractOptimizationAlgorithmCreator c)

unregister a specific creator for allocating a solver

Definition at line 74 of file optimization_algorithm_factory.cpp.

References g2o::OptimizationAlgorithmProperty::name, and g2o::AbstractOptimizationAlgorithmCreator::property().

Referenced by g2o::RegisterOptimizationAlgorithmProxy::~RegisterOptimizationAlgorithmProxy().

75  {
76  const string& name = c->property().name;
77  CreatorList::iterator foundIt = findSolver(name);
78  if (foundIt != _creator.end()) {
79  delete *foundIt;
80  _creator.erase(foundIt);
81  }
82  }
CreatorList::const_iterator findSolver(const std::string &name) const

Member Data Documentation

CreatorList g2o::OptimizationAlgorithmFactory::_creator
protected

Definition at line 111 of file optimization_algorithm_factory.h.

OptimizationAlgorithmFactory * g2o::OptimizationAlgorithmFactory::factoryInstance = 0
staticprivate

The documentation for this class was generated from the following files: