export_function_call.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 
00027 
00034 #include <acado/code_generation/export_function_call.hpp>
00035 
00036 
00037 BEGIN_NAMESPACE_ACADO
00038 
00039 
00040 //
00041 // PUBLIC MEMBER FUNCTIONS:
00042 //
00043 
00044 ExportFunctionCall::ExportFunctionCall( const std::string& _name,
00045                                                                                 const ExportArgument& _argument1,
00046                                                                                 const ExportArgument& _argument2,
00047                                                                                 const ExportArgument& _argument3,
00048                                                                                 const ExportArgument& _argument4,
00049                                                                                 const ExportArgument& _argument5,
00050                                                                                 const ExportArgument& _argument6,
00051                                                                                 const ExportArgument& _argument7,
00052                                                                                 const ExportArgument& _argument8,
00053                                                                                 const ExportArgument& _argument9
00054                                                                                 ) : ExportStatement( )
00055 {
00056         init(   _name,
00057                         _argument1,_argument2,_argument3,
00058                         _argument4,_argument5,_argument6,
00059                         _argument7,_argument8,_argument9 );
00060 }
00061 
00062 
00063 ExportFunctionCall::ExportFunctionCall( const ExportFunction& _f,
00064                                                                                 const ExportArgument& _argument1,
00065                                                                                 const ExportArgument& _argument2,
00066                                                                                 const ExportArgument& _argument3,
00067                                                                                 const ExportArgument& _argument4,
00068                                                                                 const ExportArgument& _argument5,
00069                                                                                 const ExportArgument& _argument6,
00070                                                                                 const ExportArgument& _argument7,
00071                                                                                 const ExportArgument& _argument8,
00072                                                                                 const ExportArgument& _argument9
00073                                                                                 ) : ExportStatement( )
00074 {
00075         init(   _f,
00076                         _argument1,_argument2,_argument3,
00077                         _argument4,_argument5,_argument6,
00078                         _argument7,_argument8,_argument9 );
00079 }
00080 
00081 
00082 ExportFunctionCall::ExportFunctionCall( const ExportFunctionCall& arg ) : ExportStatement( arg )
00083 {
00084         setName( arg.name );
00085 
00086         functionArguments = arg.functionArguments;
00087 }
00088 
00089 
00090 ExportFunctionCall::~ExportFunctionCall( )
00091 {
00092         clear( );
00093 }
00094 
00095 
00096 ExportFunctionCall& ExportFunctionCall::operator=( const ExportFunctionCall& arg )
00097 {
00098         if( this != &arg )
00099         {
00100                 ExportStatement::operator=( arg );
00101                 
00102                 setName( arg.name );
00103 
00104                 functionArguments = arg.functionArguments;
00105         }
00106 
00107         return *this;
00108 }
00109 
00110 ExportStatement* ExportFunctionCall::clone( ) const
00111 {
00112         return new ExportFunctionCall(*this);
00113 }
00114 
00115 
00116 
00117 returnValue ExportFunctionCall::init(   const std::string& _name,
00118                                                                                 const ExportArgument& _argument1,
00119                                                                                 const ExportArgument& _argument2,
00120                                                                                 const ExportArgument& _argument3,
00121                                                                                 const ExportArgument& _argument4,
00122                                                                                 const ExportArgument& _argument5,
00123                                                                                 const ExportArgument& _argument6,
00124                                                                                 const ExportArgument& _argument7,
00125                                                                                 const ExportArgument& _argument8,
00126                                                                                 const ExportArgument& _argument9
00127                                                                                 )
00128 {
00129         clear( );
00130 
00131         setName( _name );
00132 
00133         functionArguments.addArgument(  _argument1,_argument2,_argument3,
00134                                                                         _argument4,_argument5,_argument6,
00135                                                                         _argument7,_argument8,_argument9 );
00136 
00137         return SUCCESSFUL_RETURN;
00138 }
00139 
00140 
00141 returnValue ExportFunctionCall::init(   const ExportFunction& _f,
00142                                                                                 const ExportArgument& _argument1,
00143                                                                                 const ExportArgument& _argument2,
00144                                                                                 const ExportArgument& _argument3,
00145                                                                                 const ExportArgument& _argument4,
00146                                                                                 const ExportArgument& _argument5,
00147                                                                                 const ExportArgument& _argument6,
00148                                                                                 const ExportArgument& _argument7,
00149                                                                                 const ExportArgument& _argument8,
00150                                                                                 const ExportArgument& _argument9
00151                                                                                 )
00152 {
00153         clear( );
00154 
00155         setName( _f.getName() );
00156 
00157         if (_f.isDefined() == false)
00158         {
00159                 LOG( LVL_DEBUG ) << "ExportFunctionCall: " << _f.getName() << " is empty" << std::endl;
00160                 return SUCCESSFUL_RETURN;
00161         }
00162 
00163         functionArguments.addArgument(  _argument1,_argument2,_argument3,
00164                                                                         _argument4,_argument5,_argument6,
00165                                                                         _argument7,_argument8,_argument9 );
00166 
00167         if ( _f.getNumArguments() != functionArguments.getNumArguments() )
00168         {
00169                 LOG( LVL_ERROR ) << "Function " << _f.getName()
00170                                 << " expects " << _f.getNumArguments() << " argument(s), but you provided "
00171                                 << functionArguments.getNumArguments() << std::endl;
00172                 return ACADOERROR( RET_INVALID_CALL_TO_EXPORTED_FUNCTION );
00173         }
00174 
00175         return SUCCESSFUL_RETURN;
00176 }
00177 
00178 
00179 
00180 returnValue ExportFunctionCall::exportCode(     std::ostream& stream,
00181                                                                                         const std::string& _realString,
00182                                                                                         const std::string& _intString,
00183                                                                                         int _precision
00184                                                                                         ) const
00185 {
00186         if ( name.empty() == true )
00187                 return ACADOERROR( RET_MEMBER_NOT_INITIALISED );
00188 
00189         stream << name << "( ";
00190         functionArguments.exportCode(stream, _realString, _intString, _precision);
00191         stream << " );\n";
00192 
00193         return SUCCESSFUL_RETURN;
00194 }
00195 
00196 
00197 
00198 //
00199 // PROTECTED MEMBER FUNCTIONS:
00200 //
00201 
00202 returnValue ExportFunctionCall::clear( )
00203 {
00204         functionArguments.clear( );
00205         functionArguments.doNotIncludeType( );
00206 
00207         return SUCCESSFUL_RETURN;
00208 }
00209 
00210 
00211 
00212 returnValue     ExportFunctionCall::setName(    const std::string& _name
00213                                                                                         )
00214 {
00215         if ( _name.empty() == true )
00216                 return ACADOERROR( RET_INVALID_ARGUMENTS );
00217 
00218         name = _name;
00219 
00220         return SUCCESSFUL_RETURN;
00221 }
00222 
00223 
00224 
00225 CLOSE_NAMESPACE_ACADO
00226 
00227 // end of file.


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