export_function_call.cpp
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 
27 
35 
36 
38 
39 
40 //
41 // PUBLIC MEMBER FUNCTIONS:
42 //
43 
44 ExportFunctionCall::ExportFunctionCall( const std::string& _name,
45  const ExportArgument& _argument1,
46  const ExportArgument& _argument2,
47  const ExportArgument& _argument3,
48  const ExportArgument& _argument4,
49  const ExportArgument& _argument5,
50  const ExportArgument& _argument6,
51  const ExportArgument& _argument7,
52  const ExportArgument& _argument8,
53  const ExportArgument& _argument9
54  ) : ExportStatement( )
55 {
56  init( _name,
57  _argument1,_argument2,_argument3,
58  _argument4,_argument5,_argument6,
59  _argument7,_argument8,_argument9 );
60 }
61 
62 
64  const ExportArgument& _argument1,
65  const ExportArgument& _argument2,
66  const ExportArgument& _argument3,
67  const ExportArgument& _argument4,
68  const ExportArgument& _argument5,
69  const ExportArgument& _argument6,
70  const ExportArgument& _argument7,
71  const ExportArgument& _argument8,
72  const ExportArgument& _argument9
73  ) : ExportStatement( )
74 {
75  init( _f,
76  _argument1,_argument2,_argument3,
77  _argument4,_argument5,_argument6,
78  _argument7,_argument8,_argument9 );
79 }
80 
81 
83 {
84  setName( arg.name );
85 
87 }
88 
89 
91 {
92  clear( );
93 }
94 
95 
97 {
98  if( this != &arg )
99  {
101 
102  setName( arg.name );
103 
105  }
106 
107  return *this;
108 }
109 
111 {
112  return new ExportFunctionCall(*this);
113 }
114 
115 
116 
117 returnValue ExportFunctionCall::init( const std::string& _name,
118  const ExportArgument& _argument1,
119  const ExportArgument& _argument2,
120  const ExportArgument& _argument3,
121  const ExportArgument& _argument4,
122  const ExportArgument& _argument5,
123  const ExportArgument& _argument6,
124  const ExportArgument& _argument7,
125  const ExportArgument& _argument8,
126  const ExportArgument& _argument9
127  )
128 {
129  clear( );
130 
131  // only append fcnPrefix iff _name does not alreads start with it
132  if ( ( _name.length() > fcnPrefix.length() ) &&
133  ( _name.compare( 0,fcnPrefix.length(),fcnPrefix ) == 0 ) )
134  {
135  setName( _name );
136  }
137  else
138  {
139  setName( fcnPrefix + "_" + _name );
140  }
141 
142  functionArguments.addArgument( _argument1,_argument2,_argument3,
143  _argument4,_argument5,_argument6,
144  _argument7,_argument8,_argument9 );
145 
146  return SUCCESSFUL_RETURN;
147 }
148 
149 
151  const ExportArgument& _argument1,
152  const ExportArgument& _argument2,
153  const ExportArgument& _argument3,
154  const ExportArgument& _argument4,
155  const ExportArgument& _argument5,
156  const ExportArgument& _argument6,
157  const ExportArgument& _argument7,
158  const ExportArgument& _argument8,
159  const ExportArgument& _argument9
160  )
161 {
162  clear( );
163 
164  setName( _f.getName() );
165 
166  if (_f.isDefined() == false)
167  {
168  LOG( LVL_DEBUG ) << "ExportFunctionCall: " << _f.getName() << " is empty" << std::endl;
169  return SUCCESSFUL_RETURN;
170  }
171 
172  functionArguments.addArgument( _argument1,_argument2,_argument3,
173  _argument4,_argument5,_argument6,
174  _argument7,_argument8,_argument9 );
175 
177  {
178  LOG( LVL_ERROR ) << "Function " << _f.getName()
179  << " expects " << _f.getNumArguments() << " argument(s), but you provided "
180  << functionArguments.getNumArguments() << std::endl;
182  }
183 
184  return SUCCESSFUL_RETURN;
185 }
186 
187 
188 
190  const std::string& _realString,
191  const std::string& _intString,
192  int _precision
193  ) const
194 {
195  if ( name.empty() == true )
197 
198  stream << name << "( ";
199  functionArguments.exportCode(stream, _realString, _intString, _precision);
200  stream << " );\n";
201 
202  return SUCCESSFUL_RETURN;
203 }
204 
205 
206 
207 //
208 // PROTECTED MEMBER FUNCTIONS:
209 //
210 
212 {
215 
216  return SUCCESSFUL_RETURN;
217 }
218 
219 
220 
221 returnValue ExportFunctionCall::setName( const std::string& _name
222  )
223 {
224  if ( _name.empty() == true )
226 
227  name = _name;
228 
229  return SUCCESSFUL_RETURN;
230 }
231 
232 
233 
235 
236 // end of file.
#define LOG(level)
Just define a handy macro for getting the logger.
Lowest level, the debug level.
returnValue setName(const std::string &_name)
ExportFunctionCall(const std::string &_name="acadoFcn", const ExportArgument &_argument1=emptyConstExportArgument, const ExportArgument &_argument2=emptyConstExportArgument, const ExportArgument &_argument3=emptyConstExportArgument, const ExportArgument &_argument4=emptyConstExportArgument, const ExportArgument &_argument5=emptyConstExportArgument, const ExportArgument &_argument6=emptyConstExportArgument, const ExportArgument &_argument7=emptyConstExportArgument, const ExportArgument &_argument8=emptyConstExportArgument, const ExportArgument &_argument9=emptyConstExportArgument)
unsigned getNumArguments() const
ExportFunctionCall & operator=(const ExportFunctionCall &arg)
Allows to pass back messages to the calling function.
Returned value is a error.
ExportStatement & operator=(const ExportStatement &arg)
#define CLOSE_NAMESPACE_ACADO
ExportArgumentList functionArguments
Defines a matrix-valued variable that can be passed as argument to exported functions.
virtual ExportStatement * clone() const
virtual bool isDefined() const
static std::string fcnPrefix
Allows to export code of a function call.
virtual returnValue exportCode(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
returnValue init(const std::string &_name="defaultFunctionName", const ExportArgument &_argument1=emptyConstExportArgument, const ExportArgument &_argument2=emptyConstExportArgument, const ExportArgument &_argument3=emptyConstExportArgument, const ExportArgument &_argument4=emptyConstExportArgument, const ExportArgument &_argument5=emptyConstExportArgument, const ExportArgument &_argument6=emptyConstExportArgument, const ExportArgument &_argument7=emptyConstExportArgument, const ExportArgument &_argument8=emptyConstExportArgument, const ExportArgument &_argument9=emptyConstExportArgument)
Base class for all kind of statements to be exported by the code generation tool. ...
Allows to export code of an arbitrary function.
virtual returnValue exportCode(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
std::string getName() const
#define BEGIN_NAMESPACE_ACADO
returnValue addArgument(const ExportArgument &_argument1, const ExportArgument &_argument2=emptyConstExportArgument, const ExportArgument &_argument3=emptyConstExportArgument, const ExportArgument &_argument4=emptyConstExportArgument, const ExportArgument &_argument5=emptyConstExportArgument, const ExportArgument &_argument6=emptyConstExportArgument, const ExportArgument &_argument7=emptyConstExportArgument, const ExportArgument &_argument8=emptyConstExportArgument, const ExportArgument &_argument9=emptyConstExportArgument)
#define ACADOERROR(retval)


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