export_statement_block.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 
40 
44 
46 
47 
48 //
49 // PUBLIC MEMBER FUNCTIONS:
50 //
51 
53 {
54 }
55 
56 
58 {
59  statements = arg.statements;
60 }
61 
62 
64 {
65  clear( );
66 }
67 
68 
70 {
71  if ( this != &arg )
72  {
73  clear( );
74 
76 
77  statements = arg.statements;
78  }
79 
80  return *this;
81 }
82 
83 
85 {
86  return new ExportStatementBlock(*this);
87 }
88 
89 
90 
92  )
93 {
94  statements.push_back( StatementPtr( _statement.clone() ) );
95 
96  return SUCCESSFUL_RETURN;
97 }
98 
99 
100 returnValue ExportStatementBlock::addStatement( const std::string& _statementString
101  )
102 {
103  ExportStatementString tmp( _statementString );
104  return addStatement( tmp );
105 }
106 
107 
109  )
110 {
111  return addStatement( _function );
112 }
113 
114 
116  const ExportArgument& _argument1,
117  const ExportArgument& _argument2,
118  const ExportArgument& _argument3,
119  const ExportArgument& _argument4,
120  const ExportArgument& _argument5,
121  const ExportArgument& _argument6,
122  const ExportArgument& _argument7,
123  const ExportArgument& _argument8,
124  const ExportArgument& _argument9
125  )
126 {
127  ExportFunctionCall tmp( _fName,
128  _argument1,_argument2,_argument3,
129  _argument4,_argument5,_argument6,
130  _argument7,_argument8,_argument9 );
131 
132  return addStatement( tmp );
133 }
134 
135 
137  const ExportArgument& _argument1,
138  const ExportArgument& _argument2,
139  const ExportArgument& _argument3,
140  const ExportArgument& _argument4,
141  const ExportArgument& _argument5,
142  const ExportArgument& _argument6,
143  const ExportArgument& _argument7,
144  const ExportArgument& _argument8,
145  const ExportArgument& _argument9
146  )
147 {
148  ExportFunctionCall tmp( _f,
149  _argument1,_argument2,_argument3,
150  _argument4,_argument5,_argument6,
151  _argument7,_argument8,_argument9 );
152 
153  return addStatement( tmp );
154 }
155 
156 
157 
159  ExportStruct _dataStruct
160  )
161 {
162  // do not declare empty variables
163  if ( _data.getDim() == 0 )
164  return SUCCESSFUL_RETURN;
165 
166  if ( ( _dataStruct == ACADO_ANY ) ||
167  ( _dataStruct == _data.getDataStruct() ) )
168  {
169  ExportDataDeclaration tmp( _data );
170  return addStatement( tmp );
171  }
172 
173  return SUCCESSFUL_RETURN;
174 }
175 
176 
178  ExportStruct _dataStruct
179  )
180 {
181  if ( ( _dataStruct == ACADO_ANY ) ||
182  ( _dataStruct == _data.getDataStruct() ) )
183  {
184  ExportDataDeclaration tmp( _data );
185  return addStatement( tmp );
186  }
187 
188  return SUCCESSFUL_RETURN;
189 }
190 
191 
193  )
194 {
195  ExportFunctionDeclaration tmp( _f );
196  return addStatement( tmp );
197 }
198 
199 
201  )
202 {
203  ExportFunctionDeclaration tmp( _f );
204  return addStatement( tmp );
205 }
206 
207 
208 
210  )
211 {
212  if ( num < 1 )
213  num = 1;
214 
215  if ( num > 10 )
216  num = 10;
217 
218  std::stringstream ss;
219  ss << std::endl;
220 
221  for (uint i = 1; i < num; ++i)
222  ss << std::endl;
223 
224  return addStatement( ss.str() );
225 }
226 
227 
228 returnValue ExportStatementBlock::addComment( const std::string& _comment
229  )
230 {
231  std::stringstream ss; ss << "/* " << _comment << " */\n";
232  return addStatement( ss.str() );
233 }
234 
235 
237  const std::string& _comment
238  )
239 {
240  std::stringstream ss;
241  for(unsigned i = 0; i < _nBlanks; ++i)
242  ss << " ";
243  ss << "/* " << _comment << " */\n";
244 
245  return addStatement( ss.str() );
246 }
247 
248 
249 
251 {
252  return statements.size();
253 }
254 
255 
256 
258  const std::string& _realString,
259  const std::string& _intString,
260  int _precision
261  ) const
262 {
263  StatementPtrArray::const_iterator it = statements.begin();
264  for(; it != statements.end(); ++it)
265  if ((*it)->exportDataDeclaration(stream, _realString, _intString, _precision) != SUCCESSFUL_RETURN)
267 
268  return SUCCESSFUL_RETURN;
269 }
270 
271 
272 
274  const std::string& _realString,
275  const std::string& _intString,
276  int _precision
277  ) const
278 {
279  StatementPtrArray::const_iterator it = statements.begin();
280  for(; it != statements.end(); ++it)
281  if ((*it)->exportCode(stream, _realString, _intString, _precision) != SUCCESSFUL_RETURN)
283 
284  return SUCCESSFUL_RETURN;
285 }
286 
287 
288 
290 {
291  return SUCCESSFUL_RETURN;
292 }
293 
295 {
296  returnValue status = _block.addStatement( _statement );
297  if (status != SUCCESSFUL_RETURN)
298  ACADOERROR( status );
299 
300  return _block;
301 }
302 
303 ExportStatementBlock& operator<<(ExportStatementBlock& _block, const std::string& _statement)
304 {
305  returnValue status = _block.addStatement( _statement );
306  if (status != SUCCESSFUL_RETURN)
307  ACADOERROR( status );
308 
309  return _block;
310 }
311 
312 //
313 // PROTECTED MEMBER FUNCTIONS:
314 //
315 
316 
317 
319 
320 // end of file.
Allows to export code containing variable declarations.
Allows to export code of an ACADO function.
Allows to pass back messages to the calling function.
Allows to export code containing function (forward) declarations.
returnValue addComment(const std::string &_comment)
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
Definition: acado_types.hpp:42
ExportStatement & operator=(const ExportStatement &arg)
#define CLOSE_NAMESPACE_ACADO
virtual returnValue exportCode(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
Defines a scalar-valued index variable to be used for exporting code.
Defines a matrix-valued variable that can be passed as argument to exported functions.
virtual ExportStatement * clone() const =0
virtual ExportStatement * clone() const
ExportStruct
Allows to export code writing a string.
Allows to export code of a function call.
ExportStruct getDataStruct() const
Base class for all kind of statements to be exported by the code generation tool. ...
Allows to export code of an arbitrary function.
virtual uint getDim() const
returnValue addStatement(const ExportStatement &_statement)
returnValue addLinebreak(uint num=1)
returnValue addDeclaration(const ExportVariable &_data, ExportStruct _dataStruct=ACADO_ANY)
friend ExportStatementBlock & operator<<(ExportStatementBlock &_block, const ExportStatement &_statement)
#define BEGIN_NAMESPACE_ACADO
std::shared_ptr< ExportStatement > StatementPtr
returnValue addFunction(const ExportFunction &_function)
virtual returnValue exportDataDeclaration(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
ExportStatementBlock & operator=(const ExportStatementBlock &rhs)
Allows to export code for a block of statements.
#define ACADOERROR(retval)
Defines a matrix-valued variable to be used for exporting code.
returnValue addFunctionCall(const std::string &_fName, 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)


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