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

#include <CEvaluationNodeLogical.h>

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

Public Types

enum  SubType {
  INVALID = 0x00FFFFFF, OR = 0x00000001, XOR = 0x00000002, AND = 0x00000003,
  EQ = 0x00000004, NE = 0x00000005, GT = 0x00000006, GE = 0x00000007,
  LT = 0x00000008, LE = 0x00000009
}
 
- 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 ()
 
 CEvaluationNodeLogical (const SubType &subType, const Data &data)
 
 CEvaluationNodeLogical (const CEvaluationNodeLogical &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 bool isBoolean () const
 
virtual ASTNode * toAST (const CCopasiDataModel *pDataModel) const
 
virtual ~CEvaluationNodeLogical ()
 
- 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 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

 CEvaluationNodeLogical ()
 

Private Attributes

CEvaluationNodempLeft
 
CEvaluationNodempRight
 

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 opertors used in an evaluation trees.

Definition at line 32 of file CEvaluationNodeLogical.h.

Member Enumeration Documentation

Enumeration of possible node types.

Enumerator
INVALID 
OR 
XOR 
AND 
EQ 
NE 
GT 
GE 
LT 
LE 

Definition at line 38 of file CEvaluationNodeLogical.h.

Constructor & Destructor Documentation

CEvaluationNodeLogical::CEvaluationNodeLogical ( )
private

Default constructor

Definition at line 21 of file CEvaluationNodeLogical.cpp.

Referenced by fromAST().

CEvaluationNodeLogical::CEvaluationNodeLogical ( const SubType subType,
const Data data 
)

Default constructor

Parameters
constSubType & subType
constData & data

Definition at line 27 of file CEvaluationNodeLogical.cpp.

References AND, EQ, GE, GT, LE, LT, CEvaluationNode::mPrecedence, CEvaluationNode::mType, NE, OR, PRECEDENCE_LOGIG_AND, PRECEDENCE_LOGIG_EQ, PRECEDENCE_LOGIG_GE, PRECEDENCE_LOGIG_GT, PRECEDENCE_LOGIG_LE, PRECEDENCE_LOGIG_LT, PRECEDENCE_LOGIG_NE, PRECEDENCE_LOGIG_OR, PRECEDENCE_LOGIG_XOR, and XOR.

28  :
30  mpLeft(NULL),
31  mpRight(NULL)
32 {
33  switch (mType & 0x00FFFFFF)
34  {
35  case OR:
37  break;
38 
39  case XOR:
41  break;
42 
43  case AND:
45  break;
46 
47  case EQ:
49  break;
50 
51  case NE:
53  break;
54 
55  case GT:
57  break;
58 
59  case GE:
61  break;
62 
63  case LT:
65  break;
66 
67  case LE:
69  break;
70  }
71 }
#define PRECEDENCE_LOGIG_AND
#define PRECEDENCE_LOGIG_XOR
#define PRECEDENCE_LOGIG_OR
#define PRECEDENCE_LOGIG_LE
#define PRECEDENCE_LOGIG_NE
#define PRECEDENCE_LOGIG_LT
#define PRECEDENCE_LOGIG_EQ
static Type subType(const Type &type)
class CEvaluationNode::CPrecedence mPrecedence
#define PRECEDENCE_LOGIG_GE
#define PRECEDENCE_LOGIG_GT
CEvaluationNodeLogical::CEvaluationNodeLogical ( const CEvaluationNodeLogical src)

Copy constructor

Parameters
constCEvaluationNodeLogical & src

Definition at line 73 of file CEvaluationNodeLogical.cpp.

73  :
74  CEvaluationNode(src),
75  mpLeft(NULL),
76  mpRight(NULL)
77 {}
CEvaluationNodeLogical::~CEvaluationNodeLogical ( )
virtual

Destructor

Definition at line 79 of file CEvaluationNodeLogical.cpp.

79 {}

Member Function Documentation

virtual void CEvaluationNodeLogical::calculate ( void  )
inlinevirtual

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

Reimplemented from CEvaluationNode.

Definition at line 84 of file CEvaluationNodeLogical.h.

References AND, EQ, GE, CEvaluationNode::getValue(), GT, LE, LT, mpLeft, mpRight, CEvaluationNode::mType, CEvaluationNode::mValue, NE, OR, and XOR.

85  {
86  switch (mType & 0x00FFFFFF)
87  {
88  case OR:
89  mValue = (mpLeft->getValue() > 0.5 ||
90  mpRight->getValue() > 0.5) ? 1.0 : 0.0;
91  break;
92 
93  case XOR:
94  mValue = ((mpLeft->getValue() > 0.5 && mpRight->getValue() < 0.5) ||
95  (mpLeft->getValue() < 0.5 && mpRight->getValue() > 0.5)) ? 1.0 : 0.0;
96  break;
97 
98  case AND:
99  mValue = (mpLeft->getValue() > 0.5 &&
100  mpRight->getValue() > 0.5) ? 1.0 : 0.0;
101  break;
102 
103  case EQ:
104  mValue = (mpLeft->getValue() == mpRight->getValue()) ? 1.0 : 0.0;
105  break;
106 
107  case NE:
108  mValue = (mpLeft->getValue() != mpRight->getValue()) ? 1.0 : 0.0;
109  break;
110 
111  case GT:
112  mValue = (mpLeft->getValue() > mpRight->getValue()) ? 1.0 : 0.0;
113  break;
114 
115  case GE:
116  mValue = (mpLeft->getValue() >= mpRight->getValue()) ? 1.0 : 0.0;
117  break;
118 
119  case LT:
120  mValue = (mpLeft->getValue() < mpRight->getValue()) ? 1.0 : 0.0;
121  break;
122 
123  case LE:
124  mValue = (mpLeft->getValue() <= mpRight->getValue()) ? 1.0 : 0.0;
125  break;
126  }
127  }
const C_FLOAT64 & getValue() const
bool CEvaluationNodeLogical::compile ( const CEvaluationTree pTree)
virtual

Compile a node;

Parameters
constCEvaluationTree * pTree
Returns
bool success;

Reimplemented from CEvaluationNode.

Definition at line 81 of file CEvaluationNodeLogical.cpp.

References CCopasiNode< std::string >::getChild(), CCopasiNode< _Data >::getSibling(), mpLeft, and mpRight.

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

82 {
83  mpLeft = static_cast<CEvaluationNode *>(getChild());
84 
85  if (mpLeft == NULL) return false;
86 
87  mpRight = static_cast<CEvaluationNode *>(mpLeft->getSibling());
88 
89  if (mpRight == NULL) return false;
90 
91  return (mpRight->getSibling() == NULL); // We must have exactly two children
92 }
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CEvaluationNode * CEvaluationNodeLogical::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 357 of file CEvaluationNodeLogical.cpp.

References CCopasiNode< _Data >::addChild(), AND, CEvaluationNodeLogical(), EQ, CEvaluationNodeConstant::FALSE, GE, GT, INVALID, LE, LT, NE, OR, CEvaluationNode::subType(), CEvaluationNodeConstant::TRUE, and XOR.

Referenced by CEvaluationTree::fromAST().

358 {
359  assert(pASTNode->getNumChildren() == children.size());
360 
361  size_t i = 0;
362  size_t iMax = children.size();
363 
365  std::string data = "";
366 
367  switch (pASTNode->getType())
368  {
369  case AST_LOGICAL_AND:
370  subType = AND;
371  data = "and";
372  break;
373 
374  case AST_LOGICAL_OR:
375  subType = OR;
376  data = "or";
377  break;
378 
379  case AST_LOGICAL_XOR:
380  subType = XOR;
381  data = "xor";
382  break;
383 
384  case AST_RELATIONAL_EQ:
385  subType = EQ;
386  data = "eq";
387  break;
388 
389  case AST_RELATIONAL_GEQ:
390  subType = GE;
391  data = "ge";
392  break;
393 
394  case AST_RELATIONAL_GT:
395  subType = GT;
396  data = "gt";
397  break;
398 
399  case AST_RELATIONAL_LEQ:
400  subType = LE;
401  data = "le";
402  break;
403 
404  case AST_RELATIONAL_LT:
405  subType = LT;
406  data = "lt";
407  break;
408 
409  case AST_RELATIONAL_NEQ:
410  subType = NE;
411  data = "ne";
412  break;
413 
414  default:
415  subType = INVALID;
416  break;
417  }
418 
419  CEvaluationNode* pNode = NULL;
420  // convert the two children
421 
422  switch (subType)
423  {
424  case AND:
425  case OR:
426  case XOR:
427 
428  // The number of chidren may vary
429  switch (iMax)
430  {
431  case 0:
432 
433  if (subType == AND)
435  else
437 
438  break;
439 
440  case 1:
441  pNode = children[0];
442  break;
443 
444  default:
445  {
446  pNode = new CEvaluationNodeLogical(subType, data);
447  CEvaluationNode * pCurrent = pNode;
448 
449  // We have at least 2 children
450  while (i < iMax - 1)
451  {
452  // add the first value
453  pCurrent->addChild(children[i++]);
454 
455  switch (iMax - i)
456  {
457  case 1:
458  // We have only 1 more child
459  pCurrent->addChild(children[i++]);
460  break;
461 
462  default:
463  // We have at least 2 more children
464  {
465  // create a new node with the same operator
466  CEvaluationNode * pTmp = new CEvaluationNodeLogical(subType, data);
467  pCurrent->addChild(pTmp);
468  pCurrent = pTmp;
469  }
470  break;
471  }
472  }
473  }
474  break;
475  }
476 
477  break;
478 
479  case EQ:
480  case NE:
481  case GE:
482  case GT:
483  case LE:
484  case LT:
485  // all these are binary
486  assert(iMax == 2);
487  pNode = new CEvaluationNodeLogical(subType, data);
488  pNode->addChild(children[0]);
489  pNode->addChild(children[1]);
490  break;
491 
492  case INVALID:
493  // do nothing
494  break;
495  }
496 
497  return pNode;
498 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static Type subType(const Type &type)
std::string CEvaluationNodeLogical::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 223 of file CEvaluationNodeLogical.cpp.

References AND, compile(), EQ, GE, CEvaluationNode::getType(), GT, LE, LT, mpLeft, mpRight, NE, OR, and CEvaluationNode::subType().

224 {
225  if (const_cast<CEvaluationNodeLogical *>(this)->compile(NULL))
226  {
227  Data DisplayString;
228  Data data;
229 
230  switch ((SubType)CEvaluationNode::subType(this->getType()))
231  {
232  case AND:
233  data = "AND";
234  break;
235 
236  case OR:
237  data = "OR";
238  break;
239 
240  /* case XOR:
241  break; */
242  case EQ:
243  data = "=";
244  break;
245 
246  case GE:
247  data = ">=";
248  break;
249 
250  case GT:
251  data = ">";
252  break;
253 
254  case LE:
255  data = "<=";
256  break;
257 
258  case LT:
259  data = "<";
260  break;
261 
262  case NE:
263  data = "<>";
264  break;
265 
266  default:
267  data = "@";
268  break;
269  }
270 
271  if (*mpLeft < * (CEvaluationNode *)this)
272  DisplayString = "(" + children[0] + ")";
273  else
274  DisplayString = children[0] + " ";
275 
276  DisplayString += data;
277 
278  if (!(*(CEvaluationNode *)this < *mpRight))
279  DisplayString += "(" + children[1] + ")";
280  else
281  DisplayString += " " + children[1];
282 
283  return DisplayString;
284  }
285  else
286  return "@";
287 }
const Type & getType() const
virtual bool compile(const CEvaluationTree *pTree)
static Type subType(const Type &type)
std::string CEvaluationNodeLogical::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 145 of file CEvaluationNodeLogical.cpp.

References AND, compile(), EQ, GE, CEvaluationNode::getType(), GT, LE, LT, mpLeft, mpRight, NE, OR, and CEvaluationNode::subType().

146 {
147  if (const_cast<CEvaluationNodeLogical *>(this)->compile(NULL))
148  {
149  Data DisplayString;
150  Data data;
151  bool isXor = false;
152 
153  switch ((SubType)CEvaluationNode::subType(this->getType()))
154  {
155  case AND:
156  data = "&&";
157  break;
158 
159  case OR:
160  data = "||";
161  break;
162 
163  case EQ:
164  data = "==";
165  break;
166 
167  case GE:
168  data = ">=";
169  break;
170 
171  case GT:
172  data = ">";
173  break;
174 
175  case LE:
176  data = "<=";
177  break;
178 
179  case LT:
180  data = "<";
181  break;
182 
183  case NE:
184  data = "!=";
185  break;
186 
187  default:
188  /*
189  * case XOR:
190  */
191  data = "!=";
192  isXor = true;
193  break;
194  }
195 
196  if (isXor)
197  DisplayString = " !";
198  else
199  DisplayString = "";
200 
201  if (*mpLeft < * (CEvaluationNode *)this)
202  DisplayString += "(" + children[0] + ")";
203  else
204  DisplayString += children[0] + " ";
205 
206  DisplayString += data;
207 
208  if (isXor)
209  DisplayString += " !";
210 
211  if (!(*(CEvaluationNode *)this < *mpRight))
212  DisplayString += "(" + children[1] + ")";
213  else
214  DisplayString += " " + children[1];
215 
216  return DisplayString;
217  }
218  else
219  return "@";
220 }
const Type & getType() const
virtual bool compile(const CEvaluationTree *pTree)
static Type subType(const Type &type)
std::string CEvaluationNodeLogical::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 120 of file CEvaluationNodeLogical.cpp.

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

121 {
122  if (const_cast<CEvaluationNodeLogical *>(this)->compile(NULL))
123  {
124  Data DisplayString;
125 
126  if (*mpLeft < * (CEvaluationNode *)this)
127  DisplayString = "(" + children[0] + ")";
128  else
129  DisplayString = children[0] + " ";
130 
131  DisplayString += mData;
132 
133  if (!(*(CEvaluationNode *)this < *mpRight))
134  DisplayString += "(" + children[1] + ")";
135  else
136  DisplayString += " " + children[1];
137 
138  return DisplayString;
139  }
140  else
141  return "@";
142 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeLogical::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 95 of file CEvaluationNodeLogical.cpp.

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

96 {
97  if (const_cast<CEvaluationNodeLogical *>(this)->compile(NULL))
98  {
99  Data Infix;
100 
101  if (*mpLeft < * (CEvaluationNode *)this)
102  Infix = "(" + children[0] + ")";
103  else
104  Infix = children[0];
105 
106  Infix += " " + mData + " ";
107 
108  if (!(*(CEvaluationNode *)this < *mpRight))
109  Infix += "(" + children[1] + ")";
110  else
111  Infix += children[1];
112 
113  return Infix;
114  }
115  else
116  return "@";
117 }
virtual bool compile(const CEvaluationTree *pTree)
std::string CEvaluationNodeLogical::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 569 of file CEvaluationNodeLogical.cpp.

References AND, compile(), EQ, GE, CEvaluationNode::getType(), GT, LE, LT, mpLeft, mpRight, NE, OR, CEvaluationNode::subType(), and XOR.

572 {
573  std::ostringstream out;
574 
575  if (const_cast<CEvaluationNodeLogical *>(this)->compile(NULL))
576  {
577  std::string data = "";
578  bool flag = false;
579 
580  switch ((SubType)CEvaluationNode::subType(this->getType()))
581  {
582  case AND:
583  data = " and ";
584  break;
585 
586  case OR:
587  data = " or ";
588  break;
589 
590  case XOR:
591  data = " xor ";
592  break;
593 
594  case EQ:
595  data = "=";
596  break;
597 
598  case GE:
599  data = "&gt;=";
600  break;
601 
602  case GT:
603  data = "&gt;";
604  break;
605 
606  case LE:
607  data = "&lt;=";
608  break;
609 
610  case LT:
611  data = "&lt;";
612  break;
613 
614  case NE:
615  data = "&NotEqual;";
616  break;
617 
618  default:
619  /*
620  *
621  */
622  data = "@";
623  break;
624  }
625 
626  out << "<mrow>" << std::endl;
627 
628  flag = ((*mpLeft < * (CEvaluationNode *)this));
629 
630  if (flag) out << "<mfenced>" << std::endl;
631 
632  out << children[0];
633 
634  if (flag) out << "</mfenced>" << std::endl;
635 
636  out << "<mo>" << data << "</mo>" << std::endl;
637 
638  flag = ((*(CEvaluationNode *)this < *mpRight));
639 
640  if (!flag) out << "<mfenced>" << std::endl;
641 
642  out << children[1];
643 
644  if (!flag) out << "</mfenced>" << std::endl;
645 
646  out << "</mrow>" << std::endl;
647  }
648 
649  return out.str();
650 }
const Type & getType() const
virtual bool compile(const CEvaluationTree *pTree)
long int flag
Definition: f2c.h:52
static Type subType(const Type &type)
std::string CEvaluationNodeLogical::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 290 of file CEvaluationNodeLogical.cpp.

References AND, compile(), EQ, GE, CEvaluationNode::getType(), GT, LE, LT, mpLeft, mpRight, NE, OR, CEvaluationNode::subType(), and CCopasiMessage::WARNING.

291 {
292  if (const_cast<CEvaluationNodeLogical *>(this)->compile(NULL))
293  {
294  Data DisplayString;
295  Data data;
296 
297  switch ((SubType)CEvaluationNode::subType(this->getType()))
298  {
299  case AND:
300  data = "&";
301  break;
302 
303  case OR:
304  data = "|";
305  break;
306 
307  case EQ:
308  data = "==";
309  break;
310 
311  case GE:
312  data = ">=";
313  break;
314 
315  case GT:
316  data = ">";
317  break;
318 
319  case LE:
320  data = "<=";
321  break;
322 
323  case LT:
324  data = "<";
325  break;
326 
327  case NE:
328  data = "!=";
329  break;
330 
331  default:
332  /* case XOR: */
334  data = "@"; //TODO
335  break;
336  }
337 
338  if (*mpLeft < * (CEvaluationNode *)this)
339  DisplayString = "(" + children[0] + ")";
340  else
341  DisplayString = children[0] + " ";
342 
343  DisplayString += data;
344 
345  if (!(*(CEvaluationNode *)this < *mpRight))
346  DisplayString += "(" + children[1] + ")";
347  else
348  DisplayString += " " + children[1];
349 
350  return DisplayString;
351  }
352  else
353  return "@"; //TODO
354 }
const Type & getType() const
virtual bool compile(const CEvaluationTree *pTree)
static Type subType(const Type &type)
bool CEvaluationNodeLogical::isBoolean ( ) const
virtual

Check whether the result is Boolean

Returns
bool isBoolean

Reimplemented from CEvaluationNode.

Definition at line 501 of file CEvaluationNodeLogical.cpp.

502 {return true;}
ASTNode * CEvaluationNodeLogical::toAST ( const CCopasiDataModel pDataModel) const
virtual

Create a new ASTNode corresponding to this OperatorNode.

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

Reimplemented from CEvaluationNode.

Definition at line 504 of file CEvaluationNodeLogical.cpp.

References CCopasiNode< _Data >::addChild(), AND, EQ, GE, CCopasiNode< std::string >::getChild(), CCopasiNode< _Data >::getSibling(), CEvaluationNode::getType(), GT, INVALID, LE, LT, NE, OR, CEvaluationNode::subType(), CEvaluationNode::toAST(), and XOR.

505 {
507  ASTNode* node = new ASTNode();
508 
509  switch (subType)
510  {
511  case AND:
512  node->setType(AST_LOGICAL_AND);
513  break;
514 
515  case OR:
516  node->setType(AST_LOGICAL_OR);
517  break;
518 
519  case XOR:
520  node->setType(AST_LOGICAL_XOR);
521  break;
522 
523  case EQ:
524  node->setType(AST_RELATIONAL_EQ);
525  break;
526 
527  case NE:
528  node->setType(AST_RELATIONAL_NEQ);
529  break;
530 
531  case GT:
532  node->setType(AST_RELATIONAL_GT);
533  break;
534 
535  case GE:
536  node->setType(AST_RELATIONAL_GEQ);
537  break;
538 
539  case LT:
540  node->setType(AST_RELATIONAL_LT);
541  break;
542 
543  case LE:
544  node->setType(AST_RELATIONAL_LEQ);
545  break;
546 
547  case INVALID:
548  break;
549 
550  default:
551  subType = INVALID;
552  break;
553  }
554 
555  if (subType != INVALID)
556  {
557  const CEvaluationNode* child1 = dynamic_cast<const CEvaluationNode*>(this->getChild());
558  const CEvaluationNode* child2 = dynamic_cast<const CEvaluationNode*>(child1->getSibling());
559  node->addChild(child1->toAST(pDataModel));
560  node->addChild(child2->toAST(pDataModel));
561  }
562 
563  return node;
564 }
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
const Type & getType() const
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static Type subType(const Type &type)
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210

Member Data Documentation

CEvaluationNode* CEvaluationNodeLogical::mpLeft
private
CEvaluationNode* CEvaluationNodeLogical::mpRight
private

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