export_algorithm_factory.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
31 #ifndef ACADO_TOOLKIT_EXPORT_ALGORITHM_FACTORY_HPP
32 #define ACADO_TOOLKIT_EXPORT_ALGORITHM_FACTORY_HPP
33 
37 
38 #include <map>
39 
41 
49 template
50 <
52  class AlgorithmBase,
54  typename AlgorithmType
55 >
57 {
58 public:
60  typedef AlgorithmBase* (*exportAlgorithmCreator)(UserInteraction* _userInteraction, const std::string &_commonHeaderName);
61 
64  {
66  return instance;
67  }
68 
70  bool registerAlgorithm( const AlgorithmType& id,
71  exportAlgorithmCreator creator)
72  {
73  bool status = associations_.insert(
74  typename idToProductMap::value_type(id, creator)).second;
75 
76  if ( status == true )
77  return true;
78 
79  return false;
80  }
81 
83  bool unregisterAlgorithm( const AlgorithmType& id)
84  {
85  bool status = associations_.erase( id ) == 1;
86 
87  if ( status == true )
88  return true;
89 
90  return false;
91  }
92 
94  AlgorithmBase* createAlgorithm( UserInteraction* _userInteraction,
95  const std::string& _commonHeaderName,
96  const AlgorithmType& id)
97  {
98  typename idToProductMap::const_iterator it = associations_.find( id );
99  if (it != associations_.end())
100  {
101  return (it->second)(_userInteraction, _commonHeaderName);
102  }
103 
104  LOG( LVL_DEBUG ) << "Algorithm is not registered!" << std::endl;
105 
106  return NULL;
107  }
108 
109 private:
110  typedef std::map<AlgorithmType, exportAlgorithmCreator> idToProductMap;
111 
112  idToProductMap associations_;
113 
115  {}
116 
118 
120 
122  {}
123 };
124 
126 
127 #endif // ACADO_TOOLKIT_EXPORT_ALGORITHM_FACTORY_HPP
#define LOG(level)
Just define a handy macro for getting the logger.
Lowest level, the debug level.
Factory for creation of exported algorithms.
bool registerAlgorithm(const AlgorithmType &id, exportAlgorithmCreator creator)
bool unregisterAlgorithm(const AlgorithmType &id)
#define CLOSE_NAMESPACE_ACADO
AlgorithmBase * createAlgorithm(UserInteraction *_userInteraction, const std::string &_commonHeaderName, const AlgorithmType &id)
std::map< AlgorithmType, exportAlgorithmCreator > idToProductMap
AlgorithmBase *(* exportAlgorithmCreator)(UserInteraction *_userInteraction, const std::string &_commonHeaderName)
Encapsulates all user interaction for setting options, logging data and plotting results.
ExportAlgorithmFactory & operator=(const ExportAlgorithmFactory &)
#define BEGIN_NAMESPACE_ACADO
static ExportAlgorithmFactory & instance()


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:33