acado_io_utils.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 
26 
37 #ifndef ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
38 #define ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
39 
40 #include <cstdlib>
41 #include <cstring>
42 
43 #include <string>
44 #include <sstream>
45 
46 #include <fstream>
47 #include <vector>
48 #include <iterator>
49 
51 
53 
57 const char LINE_SEPARATOR = '\n';
58 
62 const char TEXT_SEPARATOR = ' ';
63 
67 const char NOT_A_NUMBER[3] = { 'n', 'a', 'n' };
68 
69 const char DEFAULT_LABEL [1] = { '\0' };
70 const char DEFAULT_START_STRING [3] = { '[' , '\t', '\0' };
71 const char DEFAULT_END_STRING [4] = { '\t', ']' , '\n', '\0' };
72 const uint DEFAULT_WIDTH = 22;
74 const char DEFAULT_COL_SEPARATOR [2] = { '\t', '\0' };
75 const char DEFAULT_ROW_SEPARATOR [6] = { '\t', ']' , '\n', '[', '\t', '\0' };
76 
79  char** _startString,
80  char** _endString,
81  uint& _width,
82  uint& _precision,
83  char** _colSeparator,
84  char** _rowSeparator
85  );
86 
88 returnValue acadoCopyFile( const std::string& source,
89  const std::string& destination,
90  const std::string& commentString,
91  bool printCodegenNotice = false
92  );
93 
95 returnValue acadoCopyTemplateFile( const std::string& source,
96  const std::string& destination,
97  const std::string& commentString,
98  bool printCodegenNotice = false
99  );
100 
102 returnValue acadoCreateFolder(const std::string& name);
103 
108 
112 returnValue acadoPrintCopyrightNotice( const std::string& subpackage
113  );
114 
118 returnValue acadoPrintAutoGenerationNotice( std::ofstream& stream,
119  const std::string& commentString
120  );
121 
126 double acadoGetTime( );
127 
129 
130 namespace std
131 {
132 
134 template< class T >
135 ostream& operator<<( ostream& stream,
136  vector<T>& array
137  )
138 {
139  copy(array.begin(), array.end(), ostream_iterator< T >(stream, "\t"));
140  return stream;
141 }
142 
144 template< class T >
145 ostream& operator<<( ostream& stream,
146  vector< vector<T> >& array
147  )
148 {
149  typename vector< vector< T > >::iterator it;
150  for (it = array.begin(); it != array.end(); ++it)
151  {
152  copy(it->begin(), it->end(), ostream_iterator< T >(stream, "\t"));
153  stream << endl;
154  }
155  return stream;
156 }
157 
159 template< class T >
160 istream& operator>>( istream& stream,
161  vector< T >& array
162  )
163 {
164  while (stream.good() == true)
165  {
166  string line;
167  getline(stream, line);
168  // Skip lines beginning with "/" or "#" or empty lines
169  if (line[ 0 ] == '/' || line[ 0 ] == '#' || line.empty())
170  continue;
171 
172  stringstream ss( line );
173  T val;
174  ss >> val;
175  array.push_back( val );
176  }
177 
178  return stream;
179 }
180 
182 template< class T >
183 istream& operator>>( istream& stream,
184  vector< vector< T > >& array
185  )
186 {
187  while (stream.good() == true)
188  {
189  string line;
190  vector< T > data;
191  getline(stream, line);
192  // Skip lines beginning with "/" or "#" or empty lines
193  if (line[ 0 ] == '/' || line[ 0 ] == '#' || line.empty())
194  continue;
195 
196  stringstream ss( line );
197  copy(istream_iterator< T >( ss ), istream_iterator< T >(), back_inserter( data ));
198  // Skip lines where we could not read anything
199  if (data.size())
200  array.push_back( data );
201  }
202 
203  return stream;
204 }
205 
207 template< typename T >
208 string toString(T const& value)
209 {
210  stringstream ss;
211  ss << value;
212  return ss.str();
213 }
214 
217 {
218  IoFormatter( ostream& _stream )
219  : stream( _stream ), precision( _stream.precision() ), width( _stream.width() ), flags( _stream.flags() )
220  {}
221 
222  void set( streamsize _precision, streamsize _width, ios_base::fmtflags _flags)
223  {
224  stream.precision( _precision );
225  stream.width( _width );
226  stream.setf( _flags );
227  }
228 
229  void reset()
230  {
231  stream.precision( precision );
232  stream.width( width );
233  stream.setf( flags );
234  }
235 
236  ostream& stream;
237  streamsize precision;
238  streamsize width;
239  ios_base::fmtflags flags;
240 };
241 
242 } // namespace std
243 
244 #endif // ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
245 
246 /*
247  * end of file
248  */
const char DEFAULT_END_STRING[4]
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
const uint DEFAULT_PRECISION
returnValue acadoPrintAutoGenerationNotice(std::ofstream &stream, const std::string &commentString)
Allows to pass back messages to the calling function.
const char DEFAULT_COL_SEPARATOR[2]
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
ios_base::fmtflags flags
string toString(T const &value)
const char NOT_A_NUMBER[3]
#define CLOSE_NAMESPACE_ACADO
const char DEFAULT_START_STRING[3]
returnValue acadoPrintCopyrightNotice()
double acadoGetTime()
BEGIN_NAMESPACE_ACADO const char LINE_SEPARATOR
PrintScheme
returnValue acadoCopyFile(const std::string &source, const std::string &destination, const std::string &commentString, bool printCodegenNotice=false)
returnValue acadoCopyTemplateFile(const std::string &source, const std::string &destination, const std::string &commentString, bool printCodegenNotice=false)
IoFormatter(ostream &_stream)
const char TEXT_SEPARATOR
returnValue acadoCreateFolder(const std::string &name)
const uint DEFAULT_WIDTH
const char DEFAULT_ROW_SEPARATOR[6]
istream & operator>>(istream &stream, vector< T > &array)
#define BEGIN_NAMESPACE_ACADO
const char DEFAULT_LABEL[1]
returnValue getGlobalStringDefinitions(PrintScheme _printScheme, char **_startString, char **_endString, uint &_width, uint &_precision, char **_colSeparator, char **_rowSeparator)
ostream & operator<<(ostream &stream, vector< T > &array)


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