COPASI API  4.16.103
CEvaluationNodeDelay.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CEvaluationNodeDelay.cpp,v $
3 // $Revision: 1.11 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/16 23:11:31 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 #include <sbml/math/ASTNode.h>
15 
16 #include "copasi.h"
17 
18 #include "CEvaluationNode.h"
19 #include "CEvaluationTree.h"
21 #include "utilities/utility.h"
23 
25  CEvaluationNode(CEvaluationNode::INVALID, ""),
26  mpDelayedObject(NULL),
27  mpDeltaT(NULL)
29 
31  const Data & /* data */):
32  CEvaluationNode((Type)(CEvaluationNode::DELAY | subType), "delay"),
33  mpDelayedObject(NULL),
34  mpDeltaT(NULL)
35 {
36  switch (subType)
37  {
38  case DELAY:
39  mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
40  break;
41 
42  default:
43  fatalError();
44  break;
45  }
46 
48 }
49 
51  CEvaluationNode(src),
52  mpDelayedObject(NULL),
53  mpDeltaT(NULL)
54 {}
55 
57 
59 {
60  bool success = true;
61 
62  switch (mType & 0x00FFFFFF)
63  {
64  case DELAY:
65  mpDelayedObject = static_cast<CEvaluationNode *>(getChild());
66 
67  if (mpDelayedObject == NULL) return false;
68 
70 
71  if (mpDeltaT == NULL) return false;
72 
73  return (mpDeltaT->getSibling() == NULL); // We must have exactly 2 children
74 
75  break;
76 
77  default:
78  success = false;
79  break;
80  }
81 
82  return success;
83 }
84 
85 // virtual
86 std::string CEvaluationNodeDelay::getInfix(const std::vector< std::string > & children) const
87 {
88  if (const_cast<CEvaluationNodeDelay*>(this)->compile(NULL))
89  {
90  switch (mType & 0x00FFFFFF)
91  {
92  case DELAY:
93  return mData + "(" + children[0] + "," + children[1] + ")";
94  break;
95 
96  default:
97  break;
98  }
99  }
100 
101  return "@";
102 }
103 
104 // virtual
105 std::string CEvaluationNodeDelay::getDisplayString(const std::vector< std::string > & children) const
106 {
107  switch (mType & 0x00FFFFFF)
108  {
109  case DELAY:
110  return mData + "(" + children[0] + "," + children[1] + ")";
111  break;
112 
113  default:
114  break;
115  }
116 
117  return "@";
118 }
119 
120 // virtual
121 std::string CEvaluationNodeDelay::getCCodeString(const std::vector< std::string > & children) const
122 {
123  switch (mType & 0x00FFFFFF)
124  {
125  case DELAY:
126  return mData + "(" + children[0] + "," + children[1] + ")";
127  break;
128 
129  default:
130  break;
131  }
132 
133  return "@";
134 }
135 
136 // virtual
137 std::string CEvaluationNodeDelay::getBerkeleyMadonnaString(const std::vector< std::string > & children) const
138 {
139  switch (mType & 0x00FFFFFF)
140  {
141  case DELAY:
142  return mData + "(" + children[0] + "," + children[1] + ")";
143  break;
144 
145  default:
146  break;
147  }
148 
149  return "@";
150 }
151 
152 // virtual
153 std::string CEvaluationNodeDelay::getXPPString(const std::vector< std::string > & children) const
154 {
155  switch (mType & 0x00FFFFFF)
156  {
157  case DELAY:
158  return mData + "(" + children[0] + "," + children[1] + ")";
159  break;
160 
161  default:
162  break;
163  }
164 
165  return "@";
166 }
167 
168 // static
169 CEvaluationNode * CEvaluationNodeDelay::fromAST(const ASTNode * pASTNode, const std::vector< CEvaluationNode * > & children)
170 {
171  assert(pASTNode->getNumChildren() == children.size());
172 
173  size_t i = 0, iMax = children.size();
174 
176  std::string data = "delay";
177 
178  CEvaluationNode * pConvertedNode = new CEvaluationNodeDelay(subType, data);
179 
180  for (i = 0; i < iMax; ++i)
181  {
182  pConvertedNode->addChild(children[i]);
183  }
184 
185  pConvertedNode->compile(NULL);
186  return pConvertedNode;
187 }
188 
189 ASTNode* CEvaluationNodeDelay::toAST(const CCopasiDataModel* pDataModel) const
190 {
191  ASTNode* pNode = new ASTNode(AST_FUNCTION_DELAY);
192  const CEvaluationNode* child = static_cast<const CEvaluationNode*>(this->getChild());
193 
194  while (child)
195  {
196  pNode->addChild(child->toAST(pDataModel));
197  child = static_cast<const CEvaluationNode*>(child->getSibling());
198  }
199 
200  return pNode;
201 }
202 
203 #include "utilities/copasimathml.h"
204 
205 // virtual
206 std::string CEvaluationNodeDelay::getMMLString(const std::vector< std::string > & children,
207  bool /* expand */,
208  const std::vector< std::vector< std::string > > & /* variables */) const
209 {
210  std::ostringstream out;
211 
212  switch (mType & 0x00FFFFFF)
213  {
214  case DELAY:
215  out << "<mrow>" << std::endl;
216 
217  out << "<mi>" << mData << "</mi>" << std::endl;
218  out << "<mrow>" << std::endl;
219  out << "<mo> (</mo>" << std::endl;
220  out << "<mrow>" << std::endl;
221 
222  out << children[0];
223 
224  out << "<mo> , </mo>" << std::endl;
225 
226  out << children[1];
227 
228  out << "</mrow>" << std::endl;
229  out << "<mo>) </mo>" << std::endl;
230 
231  out << "</mrow>" << std::endl;
232  out << "</mrow>" << std::endl;
233  break;
234 
235  default:
236  break;
237  }
238 
239  return out.str();
240 }
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
virtual std::string getDisplayString(const std::vector< std::string > &children) const
#define fatalError()
ASTNode * toAST(const CCopasiDataModel *pDataModel) const
virtual std::string getInfix(const std::vector< std::string > &children) const
virtual bool compile(const CEvaluationTree *pTree)
virtual std::string getBerkeleyMadonnaString(const std::vector< std::string > &children) const
virtual std::string getXPPString(const std::vector< std::string > &children) const
CEvaluationNode * mpDeltaT
static CEvaluationNode * fromAST(const ASTNode *pASTNode, const std::vector< CEvaluationNode * > &children)
#define PRECEDENCE_FUNCTION
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
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 bool compile(const CEvaluationTree *pTree)
#define PRECEDENCE_NUMBER
CEvaluationNode * mpDelayedObject
virtual std::string getCCodeString(const std::vector< std::string > &children) const
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210