COPASI API  4.16.103
CEvaluationNodeVariable.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CEvaluationNodeVariable.cpp,v $
3 // $Revision: 1.20 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/06/15 15:32:27 $
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 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #include "copasi.h"
24 #include "CEvaluationNode.h"
25 #include "CEvaluationTree.h"
26 
27 #include "sbml/math/ASTNode.h"
28 
30  CEvaluationNode(CEvaluationNode::INVALID, ""),
31  mpTree(NULL),
32  mIndex(C_INVALID_INDEX)
34 
36  const Data & data):
37  CEvaluationNode((Type)(CEvaluationNode::VARIABLE | subType), data),
38  mpTree(NULL),
39  mIndex(C_INVALID_INDEX)
41 
43  CEvaluationNode(src),
44  mpTree(src.mpTree),
45  mIndex(src.mIndex)
46 {}
47 
49 
51 {
52  mpTree = pTree;
53 
54  if (!pTree) return false;
55 
56  mIndex = pTree->getVariableIndex(mData);
57 
58  if (mIndex == C_INVALID_INDEX) return false;
59 
60  return (getChild() == NULL); // We must not have any children.
61 }
62 
64 {
66 }
67 
69 {return mIndex;}
70 
71 ASTNode* CEvaluationNodeVariable::toAST(const CCopasiDataModel* /*pDataModel*/) const
72 {
73  ASTNode* node = new ASTNode();
74  node->setType(AST_NAME);
75  node->setName(this->getData().c_str());
76  return node;
77 }
78 
79 #include "utilities/copasimathml.h"
80 
81 // virtual
82 std::string CEvaluationNodeVariable::getMMLString(const std::vector< std::string > & /* children */,
83  bool /* expand */,
84  const std::vector< std::vector< std::string > > & variables) const
85 {
86  std::ostringstream out;
87 
88  if (mIndex < variables.size())
89  {
90  out << variables[mIndex][0] << std::endl;
91  }
92  else
93  {
94  out << "<mi>" << CMathMl::fixName(mData) << "</mi>" << std::endl;
95  }
96 
97  return out.str();
98 }
virtual size_t getVariableIndex(const std::string &name) const
static std::string fixName(const std::string &name)
Definition: copasimathml.h:33
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual const C_FLOAT64 & getVariableValue(const size_t &index) const
const CEvaluationTree * mpTree
virtual std::string getMMLString(const std::vector< std::string > &children, bool expand, const std::vector< std::vector< std::string > > &variables) const
class CEvaluationNode::CPrecedence mPrecedence
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
#define PRECEDENCE_NUMBER
virtual const Data & getData() const
Definition: CCopasiNode.h:118
virtual bool compile(const CEvaluationTree *pTree)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210