00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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
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 }
00243
00244 #endif // ACADO_TOOLKIT_ACADO_IO_UTILS_HPP
00245
00246
00247
00248