COPASI API  4.16.103
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
CEvaluationNodeChoice Class Reference

#include <CEvaluationNodeChoice.h>

Inheritance diagram for CEvaluationNodeChoice:
Inheritance graph
[legend]
Collaboration diagram for CEvaluationNodeChoice:
Collaboration graph
[legend]

Public Types

enum  SubType { INVALID = 0x00FFFFFF, IF = 0x00000000 }
 
- Public Types inherited from CEvaluationNode
enum  Type {
  INVALID = 0xFF000000, NUMBER = 0x01000000, CONSTANT = 0x02000000, OPERATOR = 0x03000000,
  OBJECT = 0x04000000, FUNCTION = 0x05000000, CALL = 0x06000000, STRUCTURE = 0x07000000,
  CHOICE = 0x08000000, VARIABLE = 0x09000000, WHITESPACE = 0x0a000000, LOGICAL = 0x0b000000,
  MV_FUNCTION = 0x0c000000, VECTOR = 0x0d000000, DELAY = 0x0e000000
}
 
- Public Types inherited from CCopasiNode< std::string >
typedef std::string Data
 

Public Member Functions

virtual void calculate ()
 
 CEvaluationNodeChoice (const SubType &subType, const Data &data)
 
 CEvaluationNodeChoice (const CEvaluationNodeChoice &src)
 
virtual bool compile (const CEvaluationTree *pTree)
 
virtual std::string getBerkeleyMadonnaString (const std::vector< std::string > &children) const
 
virtual std::string getCCodeString (const std::vector< std::string > &children) const
 
virtual std::string getDisplayString (const std::vector< std::string > &children) const
 
virtual std::string getInfix (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
 
virtual std::string getXPPString (const std::vector< std::string > &children) const
 
virtual ASTNode * toAST (const CCopasiDataModel *pDataModel) const
 
virtual ~CEvaluationNodeChoice ()
 
- Public Member Functions inherited from CEvaluationNode
void addChildren (const std::vector< CEvaluationNode * > &children)
 
std::string buildBerkeleyMadonnaString () const
 
std::string buildCCodeString () const
 
std::string buildDisplayString () const
 
std::string buildInfix () const
 
std::string buildMMLString (bool expand, const std::vector< std::vector< std::string > > &variables) const
 
std::string buildXPPString () const
 
 CEvaluationNode ()
 
 CEvaluationNode (const CEvaluationNode &src)
 
CEvaluationNodecopyBranch () const
 
CEvaluationNodecopyNode (CEvaluationNode *child1, CEvaluationNode *child2) const
 
CEvaluationNodecopyNode (const std::vector< CEvaluationNode * > &children) const
 
const CEvaluationNodefindTopMinus (const std::vector< CFunctionAnalyzer::CValue > &callParameters) const
 
const TypegetType () const
 
const C_FLOAT64getValue () const
 
const C_FLOAT64getValuePointer () const
 
virtual bool isBoolean () const
 
virtual bool operator!= (const CEvaluationNode &right) const
 
bool operator< (const CEvaluationNode &right) const
 
bool operator< (const CEvaluationNode &rhs)
 
bool operator== (const CEvaluationNode &right) const
 
void printRecursively (std::ostream &os, int indent=0) const
 
void printRecursively () const
 
virtual CEvaluationNodesimplifyNode (const std::vector< CEvaluationNode * > &children) const
 
CEvaluationNodesplitBranch (const CEvaluationNode *splitnode, bool left) const
 
virtual ~CEvaluationNode ()
 
- Public Member Functions inherited from CCopasiNode< std::string >
virtual bool addChild (CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
 
bool addSibling (CCopasiNode< Data > *pSibling, CCopasiNode< Data > *pAfter=NULL)
 
 CCopasiNode (CCopasiNode< Data > *pParent=NULL)
 
 CCopasiNode (const CCopasiNode< Data > &src)
 
 CCopasiNode (const Data &data, CCopasiNode< Data > *pParent=NULL)
 
bool deleteChildren ()
 
CCopasiNode< Data > * getChild ()
 
const CCopasiNode< Data > * getChild () const
 
CCopasiNode< Data > * getChild (const size_t &index)
 
const CCopasiNode< Data > * getChild (const size_t &index) const
 
virtual const DatagetData () const
 
CCopasiNode< Data > * getNext ()
 
const CCopasiNode< Data > * getNext () const
 
CCopasiNode< Data > * getNextNonChild ()
 
const CCopasiNode< Data > * getNextNonChild () const
 
size_t getNumChildren () const
 
CCopasiNode< Data > * getParent ()
 
const CCopasiNode< Data > * getParent () const
 
CCopasiNode< Data > * getSibling ()
 
const CCopasiNode< Data > * getSibling () const
 
virtual bool removeChild (CCopasiNode< Data > *pChild)
 
virtual bool setData (const Data &data)
 
virtual ~CCopasiNode ()
 

Static Public Member Functions

static CEvaluationNodefromAST (const ASTNode *pASTNode, const std::vector< CEvaluationNode * > &children)
 
- Static Public Member Functions inherited from CEvaluationNode
static CEvaluationNodecreate (const Type &type, const Data &data)
 
static bool isKeyword (const std::string &str)
 
static Type subType (const Type &type)
 
static Type type (const Type &type)
 

Private Member Functions

 CEvaluationNodeChoice ()
 

Private Attributes

CEvaluationNodempFalse
 
CEvaluationNodempIf
 
CEvaluationNodempTrue
 

Additional Inherited Members

- Protected Member Functions inherited from CEvaluationNode
 CEvaluationNode (const Type &type, const Data &data)
 
- Protected Member Functions inherited from CCopasiNode< std::string >
bool setChild (CCopasiNode< Data > *pChild)
 
bool setParent (CCopasiNode< Data > *pParent)
 
bool setSibling (CCopasiNode< Data > *pSibling)
 
- Protected Attributes inherited from CEvaluationNode
class CEvaluationNode::CPrecedence mPrecedence
 
const C_FLOAT64mpValue
 
Type mType
 
C_FLOAT64 mValue
 
- Protected Attributes inherited from CCopasiNode< std::string >
Data mData
 

Detailed Description

This is the class for nodes presenting operators used in an evaluation trees.

Definition at line 33 of file CEvaluationNodeChoice.h.

Member Enumeration Documentation

Enumeration of possible node types.

Enumerator
INVALID 
IF 

Definition at line 39 of file CEvaluationNodeChoice.h.

40  {
41  INVALID = 0x00FFFFFF,
42  IF = 0x00000000
43  };

Constructor & Destructor Documentation

CEvaluationNodeChoice::CEvaluationNodeChoice ( )
private

Default constructor

Definition at line 22 of file CEvaluationNodeChoice.cpp.

References CEvaluationNode::mPrecedence, and PRECEDENCE_NUMBER.

Referenced by fromAST().

22  :
24  mpIf(NULL),
25  mpTrue(NULL),
26  mpFalse(NULL)
class CEvaluationNode::CPrecedence mPrecedence
#define PRECEDENCE_NUMBER
CEvaluationNodeChoice::CEvaluationNodeChoice ( const SubType subType,
const Data data 
)

Default constructor

Parameters
constSubType & subType
constData & data

Definition at line 29 of file CEvaluationNodeChoice.cpp.

References fatalError, IF, CEvaluationNode::mPrecedence, and PRECEDENCE_FUNCTION.

30  :
32  mpIf(NULL),
33  mpTrue(NULL),
34  mpFalse(NULL)
35 {
36  switch (subType)
37  {
38  case IF:
39  break;
40 
41  default:
42  fatalError();
43  break;
44  }
45 
47 }
#define fatalError()
#define PRECEDENCE_FUNCTION
static Type subType(const Type &type)
class CEvaluationNode::CPrecedence mPrecedence
CEvaluationNodeChoice::CEvaluationNodeChoice ( const CEvaluationNodeChoice src)

Copy constructor

Parameters
constCEvaluationNodeChoice & src

Definition at line 49 of file CEvaluationNodeChoice.cpp.

49  :
50  CEvaluationNode(src),
51  mpIf(src.mpIf),
52  mpTrue(src.mpTrue),
53  mpFalse(src.mpFalse)
54 {}
CEvaluationNodeChoice::~CEvaluationNodeChoice ( )
virtual

Destructor

Definition at line 56 of file CEvaluationNodeChoice.cpp.

56 {}

Member Function Documentation

void CEvaluationNodeChoice::calculate ( void  )
virtual

Calculate the numerical result of the node. It is assumed that all child nodes are up to date.

Reimplemented from CEvaluationNode.

Definition at line 58 of file CEvaluationNodeChoice.cpp.

References CEvaluationNode::getValue(), mpFalse, mpIf, mpTrue, and CEvaluationNode::mValue.

59 {
60  if (mpIf->getValue() > 0.5)
61  {
62  mValue = mpTrue->getValue();
63  }
64  else
65  {
66  mValue = mpFalse->getValue();
67  }
68 }
const C_FLOAT64 & getValue() const
bool CEvaluationNodeChoice::compile ( const CEvaluationTree pTree)
virtual

Compile a node;

Parameters
constCEvaluationTree * pTree
Returns
bool success;

Reimplemented from CEvaluationNode.

Definition at line 70 of file CEvaluationNodeChoice.cpp.

References CCopasiNode< std::string >::getChild(), CCopasiNode< _Data >::getSibling(), mpFalse, mpIf, and mpTrue.

Referenced by getBerkeleyMadonnaString(), getCCodeString(), getDisplayString(), getInfix(), getMMLString(), and getXPPString().

71 {
72  mpIf = static_cast<CEvaluationNode *>(getChild());
73 
74  if (mpIf == NULL) return false;
75 
76  mpTrue = static_cast<CEvaluationNode *>(mpIf->getSibling());
77 
78  if (mpTrue == NULL) return false;
79 
80  mpFalse = static_cast<CEvaluationNode *>(mpTrue->getSibling());
81 
82  if (mpFalse == NULL) return false;
83 
84  return (mpFalse->getSibling() == NULL); // We must have exactly three children
85 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CEvaluationNode * CEvaluationNodeChoice::fromAST ( const ASTNode *  pASTNode,
const std::vector< CEvaluationNode * > &  children 
)
static

Creates a new CEvaluationNodeCall from an ASTNode and the given children

Parameters
constASTNode* pNode
conststd::vector< CEvaluationNode * > & children
Returns
CEvaluationNode * pCretedNode

Definition at line 133 of file CEvaluationNodeChoice.cpp.

References CEvaluationNodeConstant::_NaN, CCopasiNode< _Data >::addChild(), CEvaluationNodeChoice(), IF, INVALID, and CEvaluationNode::subType().

Referenced by CEvaluationTree::fromAST().

134 {
135  assert(pASTNode->getNumChildren() == children.size());
136 
137  size_t i = 0, iMax = children.size();
138 
139  // a piecewise function definition can have zero or more children.
140  if (iMax == 0)
141  {
142  // create a NaN node
144  }
145 
146  if (iMax == 1)
147  {
148  // this must be the otherwise
149  // It is not clearly specified what happens if there are no pieces, but
150  // an otherwise. I would assume that in this case, the otherwise always
151  // takes effect
152 
153  return children[0];
154  }
155 
157  std::string data = "";
158 
159  switch (pASTNode->getType())
160  {
161  case AST_FUNCTION_PIECEWISE:
162  subType = IF;
163  data = "if";
164  break;
165 
166  default:
167  subType = INVALID;
168  break;
169  }
170 
171  CEvaluationNodeChoice * pNode = new CEvaluationNodeChoice(subType, data);
172  CEvaluationNode * pCurrent = pNode;
173 
174  // We have at least 2 children
175  while (i < iMax - 1)
176  {
177  // add the condition
178  pCurrent->addChild(children[i + 1]);
179  // the true value
180  pCurrent->addChild(children[i]);
181 
182  i += 2;
183 
184  switch (iMax - i)
185  {
186  case 0:
187  // We are missing the false value
189  break;
190 
191  case 1:
192  // the false value
193  pCurrent->addChild(children[i++]);
194  break;
195 
196  default:
197  // We have at least 2 more children
198  {
199  // create a new piecewise as the false value
200  CEvaluationNode * pTmp = new CEvaluationNodeChoice(subType, data);
201  pCurrent->addChild(pTmp);
202  pCurrent = pTmp;
203  }
204  break;
205  }
206  }
207 
208  return pNode;
209 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static Type subType(const Type &type)
std::string CEvaluationNodeChoice::getBerkeleyMadonnaString ( const std::vector< std::string > &  children) const
virtual

Retrieve the display string of the node and its eventual child nodes in Berkeley Madonna format.

Returns
const Data & value

Reimplemented from CEvaluationNode.

Definition at line 115 of file CEvaluationNodeChoice.cpp.

References compile().

116 {
117  if (const_cast<CEvaluationNodeChoice *>(this)->compile(NULL))
118  return "(if " + children[0] + " then " + children[1] + " else " + children[2] + ")";
119  else
120  return "@";
121 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeChoice::getCCodeString ( const std::vector< std::string > &  children) const
virtual

Retrieve the display string of the node and its eventual child nodes in C .

Returns
const Data & value

Reimplemented from CEvaluationNode.

Definition at line 106 of file CEvaluationNodeChoice.cpp.

References compile().

107 {
108  if (const_cast<CEvaluationNodeChoice *>(this)->compile(NULL))
109  return "(" + children[0] + " ? " + children[1] + " : " + children[2] + ")";
110  else
111  return "@";
112 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeChoice::getDisplayString ( const std::vector< std::string > &  children) const
virtual

Retrieve the display string of the node and its eventual child nodes.

Returns
const Data & value

Reimplemented from CEvaluationNode.

Definition at line 97 of file CEvaluationNodeChoice.cpp.

References compile(), and CCopasiNode< std::string >::mData.

98 {
99  if (const_cast<CEvaluationNodeChoice *>(this)->compile(NULL))
100  return mData + "(" + children[0] + "," + children[1] + "," + children[2] + ")";
101  else
102  return "@";
103 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeChoice::getInfix ( const std::vector< std::string > &  children) const
virtual

Retrieve the infix value of the node and its eventual child nodes.

Returns
const Data & value

Reimplemented from CEvaluationNode.

Definition at line 88 of file CEvaluationNodeChoice.cpp.

References compile(), and CCopasiNode< std::string >::mData.

89 {
90  if (const_cast<CEvaluationNodeChoice *>(this)->compile(NULL))
91  return mData + "(" + children[0] + "," + children[1] + "," + children[2] + ")";
92  else
93  return "@";
94 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeChoice::getMMLString ( const std::vector< std::string > &  children,
bool  expand,
const std::vector< std::vector< std::string > > &  variables 
) const
virtual

Build the MathML string

Parameters
conststd::vector< std::string > & children
boolexpand = true
conststd::vector< std::vector< std::string > > & variables
Returns
std::string MMLString

Reimplemented from CEvaluationNode.

Definition at line 231 of file CEvaluationNodeChoice.cpp.

References compile().

234 {
235  std::ostringstream out;
236 
237  if (const_cast<CEvaluationNodeChoice *>(this)->compile(NULL))
238  {
239  out << "<mrow>" << std::endl;
240  out << "<mo> {</mo>" << std::endl;
241  out << "<mtable>" << std::endl;
242 
243  out << "<mtr>" << std::endl;
244 
245  out << "<mtd>" << std::endl;
246  out << children[0];
247  out << "<mo> , </mo>" << std::endl;
248  out << "</mtd>" << std::endl;
249 
250  out << "<mtd>" << std::endl;
251  out << children[1];
252 
253  out << "</mtd>" << std::endl;
254 
255  out << "</mtr>" << std::endl;
256 
257  out << "<mtr>" << std::endl;
258 
259  out << "<mtd>" << std::endl;
260  out << "<mo> else, </mo>" << std::endl;
261 
262  out << "</mtd>" << std::endl;
263  out << "<mtd>" << std::endl;
264  out << children[2];
265  out << "</mtd>" << std::endl;
266 
267  out << "</mtr>" << std::endl;
268 
269  out << "</mtable>" << std::endl;
270  out << "</mrow>" << std::endl;
271  }
272 
273  return out.str();
274 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeChoice::getXPPString ( const std::vector< std::string > &  children) const
virtual

Retrieve the display string of the node and its eventual child nodes in XPPAUT format.

Returns
const Data & value

Reimplemented from CEvaluationNode.

Definition at line 124 of file CEvaluationNodeChoice.cpp.

References compile().

125 {
126  if (const_cast<CEvaluationNodeChoice *>(this)->compile(NULL))
127  return "if(" + children[0] + ")then(" + children[1] + ")else(" + children[2] + ")";
128  else
129  return "@"; //TODO
130 }
virtual bool compile(const CEvaluationTree *pTree)
ASTNode * CEvaluationNodeChoice::toAST ( const CCopasiDataModel pDataModel) const
virtual

Create a new ASTNode corresponding to this choice node.

Returns
ASTNode* return a pointer to the newly created node;

Reimplemented from CEvaluationNode.

Definition at line 211 of file CEvaluationNodeChoice.cpp.

References CCopasiNode< std::string >::getChild(), CCopasiNode< _Data >::getSibling(), and CEvaluationNode::toAST().

212 {
213  ASTNode* node = new ASTNode(AST_FUNCTION_PIECEWISE);
214  const CEvaluationNode* child1 = dynamic_cast<const CEvaluationNode*>(this->getChild());
215  assert(child1 != NULL);
216  const CEvaluationNode* child2 = dynamic_cast<const CEvaluationNode*>(child1->getSibling());
217  assert(child2 != NULL);
218  const CEvaluationNode* child3 = dynamic_cast<const CEvaluationNode*>(child2->getSibling());
219  assert(child3 != NULL);
220  // the condition is the second child to the AST node but the first child in
221  // the CEvaluationNode
222  node->addChild(child2->toAST(pDataModel));
223  node->addChild(child1->toAST(pDataModel));
224  node->addChild(child3->toAST(pDataModel));
225  return node;
226 }
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210

Member Data Documentation

CEvaluationNode* CEvaluationNodeChoice::mpFalse
private

Definition at line 148 of file CEvaluationNodeChoice.h.

Referenced by calculate(), and compile().

CEvaluationNode* CEvaluationNodeChoice::mpIf
private

Definition at line 146 of file CEvaluationNodeChoice.h.

Referenced by calculate(), and compile().

CEvaluationNode* CEvaluationNodeChoice::mpTrue
private

Definition at line 147 of file CEvaluationNodeChoice.h.

Referenced by calculate(), and compile().


The documentation for this class was generated from the following files: