export_templated_file.cpp
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 
26 
27 
35 #include <acado/code_generation/templates/templates.hpp>
36 
37 using namespace std;
38 
40 
42 {}
43 
44 
45 ExportTemplatedFile::ExportTemplatedFile( const std::string& _templateName,
46  const std::string& _fileName,
47  const std::string& _commonHeaderName,
48  const std::string& _realString,
49  const std::string& _intString,
50  int _precision,
51  const std::string& _commentString
52  ) : ExportFile( )
53 {
54  setup( _templateName,_fileName,_commonHeaderName,_realString,_intString,_precision,_commentString );
55 }
56 
57 
58 returnValue ExportTemplatedFile::setup( const std::string& _templateName,
59  const std::string& _fileName,
60  const std::string& _commonHeaderName,
61  const std::string& _realString,
62  const std::string& _intString,
63  int _precision,
64  const std::string& _commentString
65  )
66 {
67  ExportFile::setup( _fileName, _commonHeaderName, _realString, _intString, _precision, _commentString );
68 
69  folders = TEMPLATE_PATHS;
70  templateName = _templateName;
71 
72  return SUCCESSFUL_RETURN;
73 }
74 
75 
77 {
78  ifstream inputFile;
79  size_t oldPos = 0;
80  while( 1 )
81  {
82  size_t pos;
83  string tmp;
84 
85  pos = folders.find(";", oldPos);
86  tmp = folders.substr(oldPos, pos) + "/" + templateName;
87 
88  inputFile.open(tmp.c_str());
89 
90  if (inputFile.is_open() == true)
91  break;
92 
93  if (pos == string::npos)
94  {
95  LOG( LVL_ERROR ) << "Unable to open the file: " << tmp << endl;
97  }
98 
99  oldPos = pos + 1;
100  }
101 
102  string str;
103  while ( getline(inputFile, str) )
104  {
105  for (map<string, string>::const_iterator it = dictionary.begin(); it != dictionary.end(); ++it)
106  {
107  size_t pos = 0;
108  while ((pos = str.find(it->first, pos)) != string::npos)
109  {
110  str.replace(pos, it->first.length(), it->second);
111  pos += it->second.length();
112  }
113  }
114 
115  addStatement( str );
116  addStatement( "\n" );
117  }
118 
119  inputFile.close();
120 
121  return SUCCESSFUL_RETURN;
122 }
123 
#define LOG(level)
Just define a handy macro for getting the logger.
virtual returnValue setup(const std::string &_templateName, const std::string &_fileName, const std::string &_commonHeaderName="", const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16, const std::string &_commentString=std::string())
std::map< std::string, std::string > dictionary
Allows to pass back messages to the calling function.
Returned value is a error.
#define CLOSE_NAMESPACE_ACADO
Allows to export files containing automatically generated algorithms for fast model predictive contro...
Definition: export_file.hpp:52
virtual returnValue setup(const std::string &_fileName, const std::string &_commonHeaderName="", const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16, const std::string &_commentString=std::string())
Definition: export_file.cpp:62
returnValue addStatement(const ExportStatement &_statement)
#define BEGIN_NAMESPACE_ACADO
#define ACADOERROR(retval)


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