36 #include <acado/code_generation/templates/templates.hpp> 38 #if defined( __WIN32__ ) || defined( WIN32 ) 43 #elif defined( LINUX ) 47 #include <sys/types.h> 52 #warning "File I/O is not supported on this platform" 60 #define AUTOGEN_NOTICE_LENGTH 15 63 "This file was auto-generated using the ACADO Toolkit.\n",
65 "While ACADO Toolkit is free software released under the terms of\n",
66 "the GNU Lesser General Public License (LGPL), the generated code\n",
67 "as such remains the property of the user who used ACADO Toolkit\n",
68 "to generate this code. In particular, user dependent data of the code\n",
69 "do not inherit the GNU LGPL license. On the other hand, parts of the\n",
70 "generated code that are a direct copy of source code from the\n",
71 "ACADO Toolkit or the software tools it is based on, remain, as derived\n",
72 "work, automatically covered by the LGPL license.\n",
74 "ACADO Toolkit is distributed in the hope that it will be useful,\n",
75 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
76 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
83 return strlen(
string);
97 switch (_printScheme) {
119 *_startString =
new char[1];
120 (*_startString)[0] =
'\0';
122 *_endString =
new char[2];
123 (*_endString)[0] =
'\n';
124 (*_endString)[1] =
'\0';
129 *_colSeparator =
new char[2];
130 (*_colSeparator)[0] =
' ';
131 (*_colSeparator)[1] =
'\0';
133 *_rowSeparator =
new char[2];
134 (*_rowSeparator)[0] =
'\n';
135 (*_rowSeparator)[1] =
'\0';
142 *_startString =
new char[3];
143 (*_startString)[0] =
'[';
144 (*_startString)[1] =
' ';
145 (*_startString)[2] =
'\0';
147 *_endString =
new char[5];
148 (*_endString)[0] =
' ';
149 (*_endString)[1] =
']';
150 (*_endString)[2] =
';';
151 (*_endString)[3] =
'\n';
152 (*_endString)[4] =
'\0';
157 *_colSeparator =
new char[3];
158 (*_colSeparator)[0] =
',';
159 (*_colSeparator)[1] =
' ';
160 (*_colSeparator)[2] =
'\0';
162 *_rowSeparator =
new char[3];
163 (*_rowSeparator)[0] =
';';
164 (*_rowSeparator)[1] =
'\n';
165 (*_rowSeparator)[2] =
'\0';
177 const std::string& destination,
178 const std::string& commentString,
179 bool printCodegenNotice
182 std::ifstream src( source.c_str() );
183 if (src.is_open() ==
false)
185 LOG(
LVL_ERROR ) <<
"Could not open the source file: " << source << std::endl;
189 std::ofstream dst( destination.c_str() );
190 if (dst.is_open() ==
false)
192 LOG(
LVL_ERROR ) <<
"Could not open the destination file: " << destination << std::endl;
196 if (printCodegenNotice ==
BT_TRUE)
198 if (commentString.empty())
203 dst <<
" */" << endl << endl;
207 dst << commentString << endl;
223 const std::string& destination,
224 const std::string& commentString,
225 bool printCodegenNotice
228 const string folders( TEMPLATE_PATHS );
237 pos = folders.find(
";", oldPos);
238 tmp = folders.substr(oldPos, pos) +
"/" + source;
240 inputFile.open(tmp.c_str());
242 if (inputFile.is_open() ==
true)
243 return acadoCopyFile(tmp, destination, commentString, printCodegenNotice);
245 if (pos == string::npos)
251 LOG(
LVL_ERROR ) <<
"Could not open the template file: " << source << std::endl;
258 #if defined( __WIN32__ ) || defined( WIN32 ) 260 int status = _mkdir( name.c_str() );
263 if (status && err != EEXIST)
265 LOG(
LVL_ERROR ) <<
"Problem creating directory " << name << endl;
269 #elif defined( LINUX ) 271 struct stat st = {0};
273 if (stat(name.c_str(), &st) == -1)
275 if (mkdir(name.c_str(), 0700) == -1)
278 LOG(
LVL_ERROR ) <<
"Problem creating directory " << name << endl;
298 if (subpackage.empty())
299 cout <<
"\nACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.\n" \
300 "Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,\n" \
301 "Milan Vukov, Rien Quirynen, KU Leuven.\n" \
302 "Developed within the Optimization in Engineering Center (OPTEC)\n" \
303 "under supervision of Moritz Diehl. All rights reserved.\n\n" \
304 "ACADO Toolkit is distributed under the terms of the GNU Lesser\n" \
305 "General Public License 3 in the hope that it will be useful,\n" \
306 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
307 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
308 "GNU Lesser General Public License for more details.\n\n";
310 cout <<
"\nACADO Toolkit::" << subpackage << endl
311 <<
"Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,\n" \
312 "Milan Vukov, Rien Quirynen, KU Leuven.\n" \
313 "Developed within the Optimization in Engineering Center (OPTEC)\n" \
314 "under supervision of Moritz Diehl. All rights reserved.\n\n" \
315 "ACADO Toolkit is distributed under the terms of the GNU Lesser\n" \
316 "General Public License 3 in the hope that it will be useful,\n" \
317 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
318 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \
319 "GNU Lesser General Public License for more details.\n\n";
326 const std::string& commentString
329 if (stream.is_open() ==
false)
332 if (commentString.empty())
341 stream << commentString << endl;
346 stream << endl << endl;
358 double current_time = 0.0;
360 #if defined(__WIN32__) || defined(WIN32) 361 LARGE_INTEGER
counter, frequency;
362 QueryPerformanceFrequency(&frequency);
363 QueryPerformanceCounter(&counter);
364 current_time = ((double) counter.QuadPart) / ((double) frequency.QuadPart);
366 struct timeval theclock;
367 gettimeofday( &theclock,0 );
368 current_time = 1.0*theclock.tv_sec + 1.0e-6*theclock.tv_usec;
returnValue getGlobalStringDefinitions(PrintScheme _printScheme, char **_startString, char **_endString, uint &_width, uint &_precision, char **_colSeparator, char **_rowSeparator)
const char DEFAULT_END_STRING[4]
#define AUTOGEN_NOTICE_LENGTH
#define LOG(level)
Just define a handy macro for getting the logger.
const uint DEFAULT_PRECISION
static uint getStringLength(const char *string)
Allows to pass back messages to the calling function.
const char DEFAULT_COL_SEPARATOR[2]
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
returnValue acadoPrintAutoGenerationNotice(std::ofstream &stream, const std::string &commentString)
Returned value is a error.
#define CLOSE_NAMESPACE_ACADO
const char DEFAULT_START_STRING[3]
static const char * autogenerationNotice[AUTOGEN_NOTICE_LENGTH]
returnValue acadoCopyTemplateFile(const std::string &source, const std::string &destination, const std::string &commentString, bool printCodegenNotice)
returnValue acadoPrintCopyrightNotice(const std::string &subpackage)
returnValue acadoCreateFolder(const std::string &name)
returnValue acadoCopyFile(const std::string &source, const std::string &destination, const std::string &commentString, bool printCodegenNotice)
const char DEFAULT_ROW_SEPARATOR[6]
#define BEGIN_NAMESPACE_ACADO
#define ACADOERROR(retval)
#define ACADOERRORTEXT(retval, text)