export_algorithm_factory.hpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00031 #ifndef ACADO_TOOLKIT_EXPORT_ALGORITHM_FACTORY_HPP
00032 #define ACADO_TOOLKIT_EXPORT_ALGORITHM_FACTORY_HPP
00033 
00034 #include <acado/code_generation/export_algorithm.hpp>
00035 #include <acado/utils/acado_types.hpp>
00036 #include <acado/utils/acado_message_handling.hpp>
00037 
00038 #include <map>
00039 
00040 BEGIN_NAMESPACE_ACADO
00041 
00049 template
00050 <
00052         class    AlgorithmBase,
00054         typename AlgorithmType
00055 >
00056 class ExportAlgorithmFactory
00057 {
00058 public:
00060         typedef AlgorithmBase* (*exportAlgorithmCreator)(UserInteraction* _userInteraction, const std::string &_commonHeaderName);
00061 
00063         static ExportAlgorithmFactory& instance()
00064         {
00065                 static ExportAlgorithmFactory instance;
00066                 return instance;
00067         }
00068 
00070         bool registerAlgorithm( const AlgorithmType& id,
00071                                                                         exportAlgorithmCreator creator)
00072         {
00073                 bool status = associations_.insert(
00074                                 typename idToProductMap::value_type(id, creator)).second;
00075 
00076                 if ( status == true )
00077                         return true;
00078 
00079                 return false;
00080         }
00081 
00083         bool unregisterAlgorithm(       const AlgorithmType& id)
00084         {
00085                 bool status = associations_.erase( id ) == 1;
00086 
00087                 if ( status == true )
00088                         return true;
00089 
00090                 return false;
00091         }
00092 
00094         AlgorithmBase* createAlgorithm( UserInteraction* _userInteraction,
00095                                                                         const std::string& _commonHeaderName,
00096                                                                         const AlgorithmType& id)
00097         {
00098                 typename idToProductMap::const_iterator it = associations_.find( id );
00099                 if (it != associations_.end())
00100                 {
00101                         return (it->second)(_userInteraction, _commonHeaderName);
00102                 }
00103 
00104                 LOG( LVL_DEBUG ) << "Algorithm is not registered!" << std::endl;
00105 
00106                 return NULL;
00107         }
00108 
00109 private:
00110         typedef std::map<AlgorithmType, exportAlgorithmCreator> idToProductMap;
00111 
00112         idToProductMap associations_;
00113 
00114         ExportAlgorithmFactory()
00115         {}
00116 
00117         ExportAlgorithmFactory(const ExportAlgorithmFactory&);
00118 
00119         ExportAlgorithmFactory& operator=(const ExportAlgorithmFactory&);
00120 
00121         ~ExportAlgorithmFactory()
00122         {}
00123 };
00124 
00125 CLOSE_NAMESPACE_ACADO
00126 
00127 #endif // ACADO_TOOLKIT_EXPORT_ALGORITHM_FACTORY_HPP


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:09