00001 // g2o - General Graph Optimization 00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard 00003 // 00004 // g2o is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU Lesser General Public License as published 00006 // by the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // g2o is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #ifndef SOLVER_FACTORY_H 00018 #define SOLVER_FACTORY_H 00019 00020 #include "solver_property.h" 00021 00022 #include <list> 00023 00024 namespace g2o { 00025 00026 // forward decl 00027 class Solver; 00028 struct SparseOptimizer; 00029 00036 class AbstractSolverCreator 00037 { 00038 public: 00039 AbstractSolverCreator(const SolverProperty& p); 00041 virtual Solver* construct(SparseOptimizer* optimizer) = 0; 00043 const SolverProperty& property() const { return _property;} 00044 protected: 00045 SolverProperty _property; 00046 }; 00047 00055 class SolverFactory 00056 { 00057 public: 00058 typedef std::list<AbstractSolverCreator*> CreatorList; 00059 00061 static SolverFactory* instance(); 00062 00064 static void destroy(); 00065 00069 void registerSolver(AbstractSolverCreator* c); 00070 00074 Solver* construct(const std::string& tag, SparseOptimizer* optimizer, SolverProperty& solverProperty) const; 00075 00077 void listSolvers(std::ostream& os) const; 00078 00080 const CreatorList& creatorList() const { return _creator;} 00081 00082 protected: 00083 SolverFactory(); 00084 ~SolverFactory(); 00085 00086 CreatorList _creator; 00087 00088 CreatorList::const_iterator findSolver(const std::string& name) const; 00089 CreatorList::iterator findSolver(const std::string& name); 00090 00091 private: 00092 static SolverFactory* factoryInstance; 00093 }; 00094 00095 } 00096 00097 #endif