export_statement_block.cpp
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 
00034 #include <acado/code_generation/export_statement_block.hpp>
00035 #include <acado/code_generation/export_function.hpp>
00036 #include <acado/code_generation/export_acado_function.hpp>
00037 #include <acado/code_generation/export_function_call.hpp>
00038 #include <acado/code_generation/export_statement_string.hpp>
00039 #include <acado/code_generation/export_function_declaration.hpp>
00040 
00041 #include <acado/code_generation/export_variable.hpp>
00042 #include <acado/code_generation/export_index.hpp>
00043 #include <acado/code_generation/export_data_declaration.hpp>
00044 
00045 BEGIN_NAMESPACE_ACADO
00046 
00047 
00048 //
00049 // PUBLIC MEMBER FUNCTIONS:
00050 //
00051 
00052 ExportStatementBlock::ExportStatementBlock( ) : ExportStatement( )
00053 {
00054 }
00055 
00056 
00057 ExportStatementBlock::ExportStatementBlock( const ExportStatementBlock& arg ) : ExportStatement( arg )
00058 {
00059         statements = arg.statements;
00060 }
00061 
00062 
00063 ExportStatementBlock::~ExportStatementBlock( )
00064 {
00065         clear( );
00066 }
00067 
00068 
00069 ExportStatementBlock& ExportStatementBlock::operator=( const ExportStatementBlock& arg )
00070 {
00071         if ( this != &arg )
00072         {
00073                 clear( );
00074 
00075                 ExportStatement::operator=( arg );
00076 
00077                 statements = arg.statements;
00078         }
00079 
00080         return *this;
00081 }
00082 
00083 
00084 ExportStatement* ExportStatementBlock::clone( ) const
00085 {
00086         return new ExportStatementBlock(*this);
00087 }
00088 
00089 
00090 
00091 returnValue ExportStatementBlock::addStatement( const ExportStatement& _statement
00092                                                                                                 )
00093 {
00094         statements.push_back( StatementPtr( _statement.clone() ) );
00095         
00096         return SUCCESSFUL_RETURN;
00097 }
00098 
00099 
00100 returnValue ExportStatementBlock::addStatement( const std::string& _statementString
00101                                                                                                 )
00102 {
00103         ExportStatementString tmp( _statementString );
00104         return addStatement( tmp );
00105 }
00106 
00107 
00108 returnValue ExportStatementBlock::addFunction(  const ExportFunction& _function
00109                                                                                                 )
00110 {
00111         return addStatement( _function );
00112 }
00113 
00114 
00115 returnValue ExportStatementBlock::addFunctionCall(      const std::string& _fName,
00116                                                                                                         const ExportArgument& _argument1,
00117                                                                                                         const ExportArgument& _argument2,
00118                                                                                                         const ExportArgument& _argument3,
00119                                                                                                         const ExportArgument& _argument4,
00120                                                                                                         const ExportArgument& _argument5,
00121                                                                                                         const ExportArgument& _argument6,
00122                                                                                                         const ExportArgument& _argument7,
00123                                                                                                         const ExportArgument& _argument8,
00124                                                                                                         const ExportArgument& _argument9
00125                                                                                                         )
00126 {
00127         ExportFunctionCall tmp( _fName,
00128                                                         _argument1,_argument2,_argument3,
00129                                                         _argument4,_argument5,_argument6,
00130                                                         _argument7,_argument8,_argument9 );
00131 
00132         return addStatement( tmp );
00133 }
00134 
00135 
00136 returnValue ExportStatementBlock::addFunctionCall(      const ExportFunction& _f,
00137                                                                                                         const ExportArgument& _argument1,
00138                                                                                                         const ExportArgument& _argument2,
00139                                                                                                         const ExportArgument& _argument3,
00140                                                                                                         const ExportArgument& _argument4,
00141                                                                                                         const ExportArgument& _argument5,
00142                                                                                                         const ExportArgument& _argument6,
00143                                                                                                         const ExportArgument& _argument7,
00144                                                                                                         const ExportArgument& _argument8,
00145                                                                                                         const ExportArgument& _argument9
00146                                                                                                         )
00147 {
00148         ExportFunctionCall tmp( _f,
00149                                                         _argument1,_argument2,_argument3,
00150                                                         _argument4,_argument5,_argument6,
00151                                                         _argument7,_argument8,_argument9 );
00152 
00153         return addStatement( tmp );
00154 }
00155 
00156 
00157 
00158 returnValue ExportStatementBlock::addDeclaration(       const ExportVariable& _data,
00159                                                                                                         ExportStruct _dataStruct
00160                                                                                                         )
00161 {
00162         // do not declare empty variables
00163         if ( _data.getDim() == 0 )
00164                 return SUCCESSFUL_RETURN;
00165 
00166         if ( ( _dataStruct == ACADO_ANY ) ||
00167                  ( _dataStruct == _data.getDataStruct() ) )
00168         {
00169                 ExportDataDeclaration tmp( _data );
00170                 return addStatement( tmp );
00171         }
00172         
00173         return SUCCESSFUL_RETURN;
00174 }
00175 
00176 
00177 returnValue ExportStatementBlock::addDeclaration(       const ExportIndex& _data,
00178                                                                                                         ExportStruct _dataStruct
00179                                                                                                         )
00180 {
00181         if ( ( _dataStruct == ACADO_ANY ) ||
00182                  ( _dataStruct == _data.getDataStruct() ) )
00183         {
00184                 ExportDataDeclaration tmp( _data );
00185                 return addStatement( tmp );
00186         }
00187         
00188         return SUCCESSFUL_RETURN;
00189 }
00190 
00191 
00192 returnValue ExportStatementBlock::addDeclaration(       const ExportFunction& _f
00193                                                                                                         )
00194 {
00195         ExportFunctionDeclaration tmp( _f );
00196         return addStatement( tmp );
00197 }
00198 
00199 
00200 returnValue ExportStatementBlock::addDeclaration(       const ExportAcadoFunction& _f
00201                                                                                                         )
00202 {
00203         ExportFunctionDeclaration tmp( _f );
00204         return addStatement( tmp );
00205 }
00206 
00207 
00208 
00209 returnValue ExportStatementBlock::addLinebreak( uint num
00210                                                                                                 )
00211 {
00212         if ( num < 1 )
00213                 num = 1;
00214         
00215         if ( num > 10 )
00216                 num = 10;
00217 
00218         std::stringstream ss;
00219         ss << std::endl;
00220 
00221         for (uint i = 1; i < num; ++i)
00222                 ss << std::endl;
00223 
00224         return addStatement( ss.str() );
00225 }
00226 
00227 
00228 returnValue ExportStatementBlock::addComment(   const std::string& _comment
00229                                                                                                 )
00230 {
00231         std::stringstream ss; ss << "/* " << _comment << " */\n";
00232         return addStatement( ss.str() );
00233 }
00234 
00235 
00236 returnValue ExportStatementBlock::addComment(   uint _nBlanks,
00237                                                                                                 const std::string& _comment
00238                                                                                                 )
00239 {
00240         std::stringstream ss;
00241         for(unsigned i = 0; i < _nBlanks; ++i)
00242                 ss << " ";
00243         ss << "/* " << _comment << " */\n";
00244 
00245         return addStatement( ss.str() );
00246 }
00247 
00248 
00249 
00250 uint ExportStatementBlock::getNumStatements( ) const
00251 {
00252         return statements.size();
00253 }
00254 
00255 
00256 
00257 returnValue ExportStatementBlock::exportDataDeclaration(        std::ostream& stream,
00258                                                                                                                         const std::string& _realString,
00259                                                                                                                         const std::string& _intString,
00260                                                                                                                         int _precision
00261                                                                                                                         ) const
00262 {
00263         StatementPtrArray::const_iterator it = statements.begin();
00264         for(; it != statements.end(); ++it)
00265                 if ((*it)->exportDataDeclaration(stream, _realString, _intString, _precision) != SUCCESSFUL_RETURN)
00266                         return ACADOERROR( RET_UNABLE_TO_EXPORT_STATEMENT );
00267 
00268         return SUCCESSFUL_RETURN;
00269 }
00270 
00271 
00272 
00273 returnValue ExportStatementBlock::exportCode(   std::ostream& stream,
00274                                                                                                 const std::string& _realString,
00275                                                                                                 const std::string& _intString,
00276                                                                                                 int _precision
00277                                                                                                 ) const
00278 {
00279         StatementPtrArray::const_iterator it = statements.begin();
00280         for(; it != statements.end(); ++it)
00281                 if ((*it)->exportCode(stream, _realString, _intString, _precision) != SUCCESSFUL_RETURN)
00282                         return ACADOERROR( RET_UNABLE_TO_EXPORT_STATEMENT );
00283 
00284         return SUCCESSFUL_RETURN;
00285 }
00286 
00287 
00288 
00289 returnValue ExportStatementBlock::clear( )
00290 {
00291         return SUCCESSFUL_RETURN;
00292 }
00293 
00294 ExportStatementBlock& operator<<(ExportStatementBlock& _block, const ExportStatement& _statement)
00295 {
00296         returnValue status = _block.addStatement( _statement );
00297         if (status != SUCCESSFUL_RETURN)
00298                 ACADOERROR( status );
00299 
00300         return _block;
00301 }
00302 
00303 ExportStatementBlock& operator<<(ExportStatementBlock& _block, const std::string& _statement)
00304 {
00305         returnValue status = _block.addStatement( _statement );
00306         if (status != SUCCESSFUL_RETURN)
00307                 ACADOERROR( status );
00308 
00309         return _block;
00310 }
00311 
00312 //
00313 // PROTECTED MEMBER FUNCTIONS:
00314 //
00315 
00316 
00317 
00318 CLOSE_NAMESPACE_ACADO
00319 
00320 // end of file.


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