COPASI API  4.16.103
CEvaluationNodeConstant.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2005 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #ifdef WIN32
16 # define _USE_MATH_DEFINES
17 #endif
18 
19 #include <cmath>
20 #include <string>
21 
22 #include "copasi.h"
23 
24 #include "CEvaluationNode.h"
25 
26 #include "sbml/math/ASTNode.h"
27 
29  CEvaluationNode(CEvaluationNode::INVALID, "")
31 
33  const Data & data):
34  CEvaluationNode((Type)(CEvaluationNode::CONSTANT | subType), data)
35 {
36  switch ((SubType) subType)
37  {
38  case PI:
39  mValue = M_PI;
40  break;
41 
42  case EXPONENTIALE:
43  mValue = M_E;
44  break;
45 
46  case TRUE:
47  mValue = 1.0;
48  break;
49 
50  case FALSE:
51  mValue = 0.0;
52  break;
53 
54  case _INFINITY:
55  mValue = std::numeric_limits<C_FLOAT64>::infinity();
56  break;
57 
58  case _NaN:
59  mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
60  break;
61 
62  default:
63  mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
64  break;
65  }
66 
68 }
69 
71  CEvaluationNode(src)
72 {}
73 
75 
76 // virtual
77 std::string CEvaluationNodeConstant::getCCodeString(const std::vector< std::string > & /* children */) const
78 {
79  std::string data = "";
80 
82 
83  switch (subType)
84  {
85  case PI:
86  data = "PI";
87  break;
88 
89  case EXPONENTIALE:
90  data = "EXPONENTIALE";
91  break;
92 
93  case TRUE:
94  data = "TRUE";
95  break;
96 
97  case FALSE:
98  data = "FALSE";
99  break;
100 
101  case _INFINITY:
102  data = "INFINITY";
103  break;
104 
105  case _NaN:
106  data = "NaN";
107  break;
108 
109  default:
110  data = "@";
111  break;
112  }
113 
114  return data;
115 }
116 
117 // virtual
118 std::string CEvaluationNodeConstant::getBerkeleyMadonnaString(const std::vector< std::string > & /* children */) const
119 {
120  std::ostringstream DisplayString;
121  std::string data = "";
122 
124 
125  switch (subType)
126  {
127  case PI:
128  data = "PI";
129  break;
130 
131  case EXPONENTIALE:
132  case TRUE:
133  case FALSE:
134  case _INFINITY:
135  case _NaN:
136  DisplayString << mValue;
137  data = DisplayString.str();
138  break;
139 
140  default:
141  data = "@";
142  break;
143  }
144 
145  return data;
146 }
147 
148 // virtual
149 std::string CEvaluationNodeConstant::getXPPString(const std::vector< std::string > & /* children */) const
150 {
151  std::ostringstream DisplayString;
152  std::string data = "";
153 
155 
156  switch (subType)
157  {
158  case PI:
159  data = "pi";
160  break;
161 
162  case EXPONENTIALE:
163  case TRUE:
164  case FALSE:
165  case _INFINITY:
166  case _NaN:
167  DisplayString << mValue;
168  data = DisplayString.str();
169  break;
170 
171  default:
172  data = "@"; //TODO
173  break;
174  }
175 
176  return data;
177 }
178 
179 // static
180 CEvaluationNode * CEvaluationNodeConstant::fromAST(const ASTNode * pASTNode, const std::vector< CEvaluationNode * > & children)
181 {
182  assert(pASTNode->getNumChildren() == children.size());
183  assert(children.size() == 0);
184 
186  std::string data = "";
187 
188  switch (pASTNode->getType())
189  {
190  case AST_CONSTANT_E:
191  subType = EXPONENTIALE;
192  data = "EXPONENTIALE";
193  break;
194 
195  case AST_CONSTANT_PI:
196  subType = PI;
197  data = "PI";
198  break;
199 
200  case AST_CONSTANT_TRUE:
201  subType = TRUE;
202  data = "TRUE";
203  break;
204 
205  case AST_CONSTANT_FALSE:
206  subType = FALSE;
207  data = "FALSE";
208  break;
209 
210  default:
211  subType = INVALID;
212  break;
213  }
214 
215  return new CEvaluationNodeConstant(subType, data);
216 }
217 
218 // virtual
220 {
222  {
223  case TRUE:
224  case FALSE:
225  return true;
226 
227  default:
228  return false;
229  }
230 }
231 
232 ASTNode* CEvaluationNodeConstant::toAST(const CCopasiDataModel* /*pDataModel*/) const
233 {
235  ASTNode* node = new ASTNode();
236 
237  switch (subType)
238  {
239  case PI:
240  node->setType(AST_CONSTANT_PI);
241  break;
242 
243  case EXPONENTIALE:
244  node->setType(AST_CONSTANT_E);
245  break;
246 
247  case TRUE:
248  node->setType(AST_CONSTANT_TRUE);
249  break;
250 
251  case FALSE:
252  node->setType(AST_CONSTANT_FALSE);
253  break;
254 
255  case _INFINITY:
256  node->setType(AST_REAL);
257  node->setValue(std::numeric_limits<C_FLOAT64>::infinity());
258  break;
259 
260  case _NaN:
261  case INVALID:
262  node->setType(AST_REAL);
263  node->setValue(std::numeric_limits<C_FLOAT64>::quiet_NaN());
264  break;
265  }
266 
267  return node;
268 }
269 
270 #include "utilities/copasimathml.h"
271 
272 // virtual
273 std::string CEvaluationNodeConstant::getMMLString(const std::vector< std::string > & /* children */,
274  bool /* expand */,
275  const std::vector< std::vector< std::string > > & /* variables */) const
276 {
277  std::ostringstream out;
278 
279  std::string data = "";
280 
281  switch ((SubType)CEvaluationNode::subType(this->getType()))
282  {
283  case PI:
284  data = "&pi;";
285  break;
286 
287  case EXPONENTIALE:
288  data = "e";
289  break;
290 
291  case TRUE:
292  data = "true";
293  break;
294 
295  case FALSE:
296  data = "false";
297  break;
298 
299  case _INFINITY:
300  data = "&infin;";
301  break;
302 
303  case _NaN:
304  data = "NaN";
305  break;
306 
307  default:
308  data = "@";
309  break;
310  }
311 
312  out << "<mi>" << data << "</mi>" << std::endl;
313 
314  return out.str();
315 }
const Type & getType() const
virtual std::string getCCodeString(const std::vector< std::string > &children) const
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
static CEvaluationNode * fromAST(const ASTNode *pASTNode, const std::vector< CEvaluationNode * > &children)
virtual std::string getXPPString(const std::vector< std::string > &children) const
virtual std::string getMMLString(const std::vector< std::string > &children, bool expand, const std::vector< std::vector< std::string > > &variables) const
static Type subType(const Type &type)
class CEvaluationNode::CPrecedence mPrecedence
virtual std::string getBerkeleyMadonnaString(const std::vector< std::string > &children) const
#define PRECEDENCE_NUMBER