acado_io_utils.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 
00026 
00037 #ifndef ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
00038 #define ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
00039 
00040 #include <cstdlib>
00041 #include <cstring>
00042 
00043 #include <string>
00044 #include <sstream>
00045 
00046 #include <fstream>
00047 #include <vector>
00048 #include <iterator>
00049 
00050 #include <acado/utils/acado_message_handling.hpp>
00051 
00052 BEGIN_NAMESPACE_ACADO
00053 
00057 const char LINE_SEPARATOR = '\n';
00058 
00062 const char TEXT_SEPARATOR = ' ';
00063 
00067 const char NOT_A_NUMBER[3] = { 'n', 'a', 'n' };
00068 
00069 const char  DEFAULT_LABEL         [1]   = { '\0'                              };
00070 const char  DEFAULT_START_STRING  [3]   = { '[' , '\t', '\0'                  };
00071 const char  DEFAULT_END_STRING    [4]   = { '\t', ']' , '\n', '\0'            };
00072 const uint  DEFAULT_WIDTH               = 22;
00073 const uint  DEFAULT_PRECISION           = 16;
00074 const char  DEFAULT_COL_SEPARATOR [2]   = { '\t', '\0'                        };
00075 const char  DEFAULT_ROW_SEPARATOR [6]   = { '\t', ']' , '\n', '[', '\t', '\0' };
00076 
00078 returnValue getGlobalStringDefinitions( PrintScheme _printScheme,
00079                                                                                 char** _startString,
00080                                                                                 char** _endString,
00081                                                                                 uint& _width,
00082                                                                                 uint& _precision,
00083                                                                                 char** _colSeparator,
00084                                                                                 char** _rowSeparator
00085                                                                                 );
00086 
00088 returnValue acadoCopyFile(      const std::string& source,
00089                                                         const std::string& destination,
00090                                                         const std::string& commentString,
00091                                                         bool printCodegenNotice = false
00092                                                         );
00093 
00095 returnValue acadoCopyTemplateFile(      const std::string& source,
00096                                                                         const std::string& destination,
00097                                                                         const std::string& commentString,
00098                                                                         bool printCodegenNotice = false
00099                                                                         );
00100 
00102 returnValue acadoCreateFolder(const std::string& name);
00103 
00107 returnValue acadoPrintCopyrightNotice( );
00108 
00112 returnValue acadoPrintCopyrightNotice(  const std::string& subpackage
00113                                                                                 );
00114 
00118 returnValue acadoPrintAutoGenerationNotice(     std::ofstream& stream,
00119                                                                                         const std::string& commentString
00120                                                                                         );
00121 
00126 double acadoGetTime( );
00127 
00128 CLOSE_NAMESPACE_ACADO
00129 
00130 namespace std
00131 {
00132 
00134 template< class T >
00135 ostream& operator<<(    ostream& stream,
00136                                                 vector<T>& array
00137                                                 )
00138 {
00139         copy(array.begin(), array.end(), ostream_iterator< T >(stream, "\t"));
00140         return stream;
00141 }
00142 
00144 template< class T >
00145 ostream& operator<<(    ostream& stream,
00146                                                 vector< vector<T> >& array
00147                                                 )
00148 {
00149         typename vector< vector< T > >::iterator it;
00150         for (it = array.begin(); it != array.end(); ++it)
00151         {
00152                 copy(it->begin(), it->end(), ostream_iterator< T >(stream, "\t"));
00153                 stream << endl;
00154         }
00155         return stream;
00156 }
00157 
00159 template< class T >
00160 istream& operator>>(    istream& stream,
00161                                                 vector< T >& array
00162                                                 )
00163 {
00164         while (stream.good() == true)
00165         {
00166                 string line;
00167                 getline(stream, line);
00168                 // Skip lines beginning with "/" or "#" or empty lines
00169                 if (line[ 0 ] == '/' || line[ 0 ] == '#' || line.empty())
00170                         continue;
00171 
00172                 stringstream ss( line );
00173                 T val;
00174                 ss >> val;
00175                 array.push_back( val );
00176         }
00177 
00178         return stream;
00179 }
00180 
00182 template< class T >
00183 istream& operator>>(    istream& stream,
00184                                                 vector< vector< T > >& array
00185                                                 )
00186 {
00187         while (stream.good() == true)
00188         {
00189                 string line;
00190                 vector< T > data;
00191                 getline(stream, line);
00192                 // Skip lines beginning with "/" or "#" or empty lines
00193                 if (line[ 0 ] == '/' || line[ 0 ] == '#' || line.empty())
00194                         continue;
00195 
00196                 stringstream ss( line );
00197                 copy(istream_iterator< T >( ss ), istream_iterator< T >(), back_inserter( data ));
00198                 // Skip lines where we could not read anything
00199                 if (data.size())
00200                         array.push_back( data );
00201         }
00202 
00203         return stream;
00204 }
00205 
00207 template< typename T >
00208 string toString(T const& value)
00209 {
00210     stringstream ss;
00211     ss << value;
00212     return ss.str();
00213 }
00214 
00216 struct IoFormatter
00217 {
00218         IoFormatter( ostream& _stream )
00219                 : stream( _stream ), precision( _stream.precision() ), width( _stream.width() ), flags( _stream.flags() )
00220         {}
00221 
00222         void set( streamsize _precision, streamsize _width, ios_base::fmtflags _flags)
00223         {
00224                 stream.precision( _precision );
00225                 stream.width( _width );
00226                 stream.setf( _flags );
00227         }
00228 
00229         void reset()
00230         {
00231                 stream.precision( precision );
00232                 stream.width( width );
00233                 stream.setf( flags );
00234         }
00235 
00236         ostream& stream;
00237         streamsize precision;
00238         streamsize width;
00239         ios_base::fmtflags flags;
00240 };
00241 
00242 } // namespace std
00243 
00244 #endif  // ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
00245 
00246 /*
00247  *      end of file
00248  */


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