export_index_node.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  */
26 #include <sstream>
27 
29 
30 using namespace std;
31 
32 
34  const std::string& _realString,
35  const std::string& _intString,
36  int _precision
37  ) const
38 {
39  if (isGiven() == true)
40  return ACADOERRORTEXT(RET_UNABLE_TO_EXPORT_CODE, "Declaration of given indices is not supported.");
41  else if (isBinary() == true)
42  return ACADOERRORTEXT(RET_UNABLE_TO_EXPORT_CODE, "Declaration of binary node indices is not supported.");
43 
44  stream << _intString << " " << getFullName() << ";" << endl;
45 
46  return SUCCESSFUL_RETURN;
47 }
48 
49 
50 const std::string ExportIndexNode::get( ) const
51 {
52  stringstream s;
53 
54  switch ( varType )
55  {
56  case EVT_VALUE:
57  s << value;
58  break;
59 
60  case EVT_VARIABLE:
61  if (factor == 1)
62  s << getFullName();
63  else
64  s << getFullName() << " * " << factor;
65 
66  if (offset > 0)
67  s << " + " << offset;
68  else if (offset < 0)
69  s << offset;
70 
71  break;
72 
74 
75  s << "(" << left.get() << ")";
76  switch ( op )
77  {
78  case ESO_ADD:
79  s << " + ";
80  break;
81 
82  case ESO_SUBTRACT:
83  s << " - ";
84  break;
85 
86  case ESO_MULTIPLY:
87  s << " * ";
88  break;
89 
90  case ESO_DIVIDE:
91  s << " / ";
92  break;
93  case ESO_MODULO:
94  s << " % ";
95  break;
96  }
97  s << "(" << right.get() << ")";
98  break;
99  }
100 
101  return s.str();
102 }
103 
104 
106 {
107  if (varType == EVT_VALUE)
108  return value;
109 
110  if (varType == EVT_VARIABLE)
111  return -1;
112 
113  switch ( op )
114  {
115  case ESO_ADD:
116  return left.getGivenValue() + right.getGivenValue();
117 
118  case ESO_SUBTRACT:
119  return left.getGivenValue() - right.getGivenValue();
120 
121  case ESO_MULTIPLY:
122  return left.getGivenValue() * right.getGivenValue();
123 
124  case ESO_DIVIDE:
125  return left.getGivenValue() / right.getGivenValue();
126 
127  case ESO_MODULO:
128  return left.getGivenValue() % right.getGivenValue();
129 
130  default:
131  return 0;
132  }
133 }
134 
135 
137 {
138  if (varType == EVT_VALUE)
139  return true;
140 
141  return false;
142 }
143 
144 
const std::string get() const
Returns a string containing the value of the index.
virtual bool isGiven() const
Allows to pass back messages to the calling function.
#define CLOSE_NAMESPACE_ACADO
#define BEGIN_NAMESPACE_ACADO
const int getGivenValue() const
virtual returnValue exportDataDeclaration(std::ostream &stream, const std::string &_realString="real_t", const std::string &_intString="int", int _precision=16) const
#define ACADOERRORTEXT(retval, text)


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