export_index.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 
37 
39 
40 //
41 // PUBLIC MEMBER FUNCTIONS:
42 //
43 
45 {}
46 
47 
48 ExportIndex::ExportIndex( const int _value )
49 {
50  assignNode(new ExportIndexNode( _value ));
51 }
52 
53 ExportIndex::ExportIndex( const std::string& _name,
54  const std::string& _prefix )
55 {
56  assignNode(new ExportIndexNode(_name, _prefix));
57 }
58 
59 
61 {
63 }
64 
65 
67 {
68  return (const ExportIndexNode*)(ExportData::operator->());
69 }
70 
71 
73  const std::string& _realString ,
74  const std::string& _intString,
75  int _precision
76  ) const
77 {
78  return (*this)->exportDataDeclaration(stream, _realString, _intString, _precision);
79 }
80 
81 
83  const ExportIndex& _arg2
84  )
85 {
86  ExportIndex tmp;
87 
88  if (_arg1.isGiven() == true && _arg2.isGiven() == true)
89  {
90  tmp.assignNode(new ExportIndexNode(_arg1.getGivenValue() + _arg2.getGivenValue()));
91 
92  return tmp;
93  }
94 
95  if (_arg1.isVariable() == true && _arg2.isGiven() == true)
96  {
97  tmp.assignNode(new ExportIndexNode(_arg1.getName(), _arg1.getPrefix(), _arg1->getFactor(), _arg1->getOffset() + _arg2.getGivenValue()));
98 
99  return tmp;
100  }
101 
102  if (_arg1.isGiven() == true && _arg2.isVariable() == true)
103  {
104  tmp.assignNode(new ExportIndexNode(_arg2.getName(), _arg2.getPrefix(), _arg2->getFactor(), _arg2->getOffset() + _arg1.getGivenValue()));
105 
106  return tmp;
107  }
108 
109  if(_arg1.isVariable() == true && _arg2.isVariable() == true && _arg1.getFullName() == _arg2.getFullName())
110  {
111  if ((_arg1->getFactor() + _arg2->getFactor()) == 0)
112  tmp.assignNode(new ExportIndexNode(_arg1->getOffset() + _arg2->getOffset()));
113  else
114  tmp.assignNode(new ExportIndexNode(_arg1.getName(), _arg1.getPrefix(), _arg1->getFactor() + _arg2->getFactor(), _arg1->getOffset() + _arg2->getOffset()));
115  }
116  else
117  {
118  tmp.assignNode(new ExportIndexNode(ESO_ADD, _arg1, _arg2));
119  }
120 
121  return tmp;
122 }
123 
124 
126  const ExportIndex& _arg2
127  )
128 {
129  ExportIndex tmp;
130 
131  if (_arg1.isGiven() == true && _arg2.isGiven() == true)
132  {
133  tmp.assignNode(new ExportIndexNode(_arg1.getGivenValue() - _arg2.getGivenValue()));
134 
135  return tmp;
136  }
137 
138  if (_arg1.isVariable() == true && _arg2.isGiven() == true)
139  {
140  tmp.assignNode(new ExportIndexNode(_arg1.getName(), _arg1.getPrefix(), _arg1->getFactor(), _arg1->getOffset() - _arg2.getGivenValue()));
141 
142  return tmp;
143  }
144 
145  if (_arg1.isGiven() == true && _arg2.isVariable() == true)
146  {
147  tmp.assignNode(new ExportIndexNode(_arg2.getName(), _arg2.getPrefix(), -1 * _arg2->getFactor(), _arg1->getGivenValue() - _arg2->getOffset()));
148 
149  return tmp;
150  }
151 
152  if(_arg1.isVariable() == true && _arg2.isVariable() == true && _arg1.getFullName() == _arg2.getFullName())
153  {
154  if ((_arg1->getFactor() - _arg2->getFactor()) == 0)
155  tmp.assignNode(new ExportIndexNode(_arg1->getOffset() - _arg2->getOffset()));
156  else
157  tmp.assignNode(new ExportIndexNode(_arg1.getName(), _arg1.getPrefix(), _arg1->getFactor() - _arg2->getFactor(), _arg1->getOffset() - _arg2->getOffset()));
158  }
159  else
160  tmp.assignNode(new ExportIndexNode(ESO_SUBTRACT, _arg1, _arg2));
161 
162  return tmp;
163 }
164 
165 
167  const ExportIndex& _arg2
168  )
169 {
170  ExportIndex tmp;
171 
172  if (_arg1.isGiven() == true && _arg2.isGiven() == true)
173  {
174  tmp.assignNode(new ExportIndexNode(_arg1.getGivenValue() * _arg2.getGivenValue()));
175 
176  return tmp;
177  }
178 
179  if (_arg1.isVariable() == true && _arg2.isGiven() == true)
180  {
181  tmp.assignNode(new ExportIndexNode(_arg1.getName(), _arg1.getPrefix(), _arg1->getFactor() * _arg2.getGivenValue(), _arg1->getOffset() * _arg2.getGivenValue()));
182 
183  return tmp;
184  }
185 
186  if (_arg1.isGiven() == true && _arg2.isVariable() == true)
187  {
188  tmp.assignNode(new ExportIndexNode(_arg2.getName(), _arg2.getPrefix(), _arg2->getFactor() * _arg1.getGivenValue(), _arg2->getOffset() * _arg1.getGivenValue()));
189 
190  return tmp;
191  }
192 
193  tmp.assignNode(new ExportIndexNode(ESO_MULTIPLY, _arg1, _arg2));
194 
195  return tmp;
196 }
197 
198 
200  const ExportIndex& _arg2
201  )
202 {
203  ExportIndex tmp;
204 
205  if (_arg1.isGiven() == true && _arg2.isGiven() == true)
206  {
207  tmp.assignNode(new ExportIndexNode(_arg1.getGivenValue() / _arg2.getGivenValue()));
208 
209  return tmp;
210  }
211 
212  tmp.assignNode(new ExportIndexNode(ESO_DIVIDE, _arg1, _arg2));
213 
214  return tmp;
215 }
216 
218  const ExportIndex& _arg2
219  )
220 {
221  ExportIndex tmp;
222 
223  if (_arg1.isGiven() == true && _arg2.isGiven() == true)
224  {
225  tmp.assignNode(new ExportIndexNode(_arg1.getGivenValue() % _arg2.getGivenValue()));
226 
227  return tmp;
228  }
229 
230  tmp.assignNode(new ExportIndexNode(ESO_MODULO, _arg1, _arg2));
231 
232  return tmp;
233 }
234 
235 std::string operator==( const ExportIndex& _arg1,
236  const ExportIndex& _arg2
237  )
238 {
239  std::stringstream ret;
240  ret << _arg1.get() << " = " << _arg2.get() << ";\n";
241 
242  return ret.str();
243 }
244 
245 
246 const std::string ExportIndex::get( ) const
247 {
248  return (*this)->get();
249 }
250 
251 
253 {
254  return (*this)->getGivenValue();
255 }
256 
257 
258 bool ExportIndex::isGiven( ) const
259 {
260  return (*this)->isGiven();
261 }
262 
264 {
265  return (*this)->isBinary();
266 }
267 
269 {
270  return (*this)->isVariable();
271 }
272 
273 
274 ExportIndex::operator ExportArgument()
275 {
276  std::string tmpName;
277 
278  // XXX In principle, this is an ugly hack. In case when an index is given,
279  // We give it a name which is equal to its value. This is done in order
280  // To be able to simplify function calls. Most probably much more sense
281  // would make that ExportArgument is base class for this guy...
282 
283  if (isGiven() == true)
284  tmpName = std::toString(getGivenValue());
285  else
286  tmpName = (*this)->getName();
287 
288  ExportArgument tmp(tmpName, 1 , 1, (*this)->getType(), ACADO_LOCAL, true, emptyConstExportIndex);
289  tmp.setDoc( getDoc() );
290 
291  return tmp;
292 }
293 
294 
296 
297 // end of file.
void assignNode(SharedObjectNode *node)
Assign the node to a node class pointer (or null)
Allows to pass back messages to the calling function.
friend ExportIndex operator*(const ExportIndex &_arg1, const ExportIndex &_arg2)
string toString(T const &value)
#define CLOSE_NAMESPACE_ACADO
friend ExportIndex operator+(const ExportIndex &_arg1, const ExportIndex &_arg2)
Defines a scalar-valued index variable to be used for exporting code.
std::string getPrefix() const
Definition: export_data.cpp:96
const ExportIndex emptyConstExportIndex(int(0))
Defines a matrix-valued variable that can be passed as argument to exported functions.
virtual returnValue setDoc(const std::string &_doc)
virtual std::string getDoc() const
ExportIndexNode * operator->()
virtual returnValue exportDataDeclaration(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
bool isVariable() const
friend ExportIndex operator-(const ExportIndex &_arg1, const ExportIndex &_arg2)
bool isBinary() const
friend std::string operator==(const ExportIndex &_arg1, const ExportIndex &_arg2)
const int getOffset() const
std::string getFullName() const
const int getFactor() const
friend ExportIndex operator%(const ExportIndex &_arg1, const ExportIndex &_arg2)
const std::string get() const
int getGivenValue() const
bool isGiven() const
ExportDataInternal * operator->()
Definition: export_data.cpp:51
#define BEGIN_NAMESPACE_ACADO
friend ExportIndex operator/(const ExportIndex &_arg1, const ExportIndex &_arg2)
const int getGivenValue() const
std::string getName() const
Definition: export_data.cpp:86


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