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

#include <CEvaluationNodeNumber.h>

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

Public Types

enum  SubType {
  INVALID = 0x00FFFFFF, DOUBLE = 0x00000000, INTEGER = 0x00000001, ENOTATION = 0x00000002,
  RATIONALE = 0x00000003
}
 
- 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

 CEvaluationNodeNumber (const SubType &subType, const Data &data)
 
 CEvaluationNodeNumber (const C_FLOAT64 &number)
 
 CEvaluationNodeNumber (const CEvaluationNodeNumber &src)
 
virtual std::string getCCodeString (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
 
ASTNode * toAST (const CCopasiDataModel *pDataModel) const
 
virtual ~CEvaluationNodeNumber ()
 
- 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
 
virtual void calculate ()
 
 CEvaluationNode ()
 
 CEvaluationNode (const CEvaluationNode &src)
 
virtual bool compile (const CEvaluationTree *pTree)
 
CEvaluationNodecopyBranch () const
 
CEvaluationNodecopyNode (CEvaluationNode *child1, CEvaluationNode *child2) const
 
CEvaluationNodecopyNode (const std::vector< CEvaluationNode * > &children) const
 
const CEvaluationNodefindTopMinus (const std::vector< CFunctionAnalyzer::CValue > &callParameters) const
 
virtual std::string getBerkeleyMadonnaString (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
 
const TypegetType () const
 
const C_FLOAT64getValue () const
 
const C_FLOAT64getValuePointer () const
 
virtual std::string getXPPString (const std::vector< std::string > &children) 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

 CEvaluationNodeNumber ()
 

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 class for nodes presenting numbers used in an evaluation trees

Definition at line 23 of file CEvaluationNodeNumber.h.

Member Enumeration Documentation

Enumeration of possible node types.

Enumerator
INVALID 
DOUBLE 
INTEGER 
ENOTATION 
RATIONALE 

Definition at line 29 of file CEvaluationNodeNumber.h.

Constructor & Destructor Documentation

CEvaluationNodeNumber::CEvaluationNodeNumber ( )
private

Default constructor

Definition at line 26 of file CEvaluationNodeNumber.cpp.

References CEvaluationNode::mPrecedence, and PRECEDENCE_NUMBER.

Referenced by fromAST().

26  :
class CEvaluationNode::CPrecedence mPrecedence
#define PRECEDENCE_NUMBER
CEvaluationNodeNumber::CEvaluationNodeNumber ( const SubType subType,
const Data data 
)

Specific constructor

Parameters
constSubType & subType
constData & data

Definition at line 30 of file CEvaluationNodeNumber.cpp.

References DOUBLE, ENOTATION, fatalError, INTEGER, INVALID, CCopasiNode< std::string >::mData, CEvaluationNode::mPrecedence, CEvaluationNode::mValue, PRECEDENCE_NUMBER, RATIONALE, and strToDouble().

31  :
33 {
34  const char * end;
35  const char * str = mData.c_str();
36 
37  switch (subType)
38  {
39  case DOUBLE:
40  case INTEGER:
41  case ENOTATION:
42  {
43  //mValue = strToDouble(str, NULL);
44  std::istringstream in;
45  in.imbue(std::locale::classic());
46  in.str(str);
47  in >> mValue;
48  }
49  break;
50 
51  case RATIONALE:
52  str++; // Skip the '('
53  mValue = strToDouble(str, &end);
54  end++; // Skip the '/'
55  mValue /= strToDouble(end, NULL);
56  break;
57 
58  case INVALID:
59  fatalError();
60  break;
61  }
62 
64 }
#define fatalError()
static Type subType(const Type &type)
class CEvaluationNode::CPrecedence mPrecedence
double strToDouble(const char *str, char const **pTail)
Definition: utility.cpp:325
#define PRECEDENCE_NUMBER
CEvaluationNodeNumber::CEvaluationNodeNumber ( const C_FLOAT64 number)

Specific constructor

Parameters
constC_FLOAT64 & number

Definition at line 66 of file CEvaluationNodeNumber.cpp.

References CCopasiNode< std::string >::mData, CEvaluationNode::mPrecedence, and PRECEDENCE_NUMBER.

66  :
68 {
69  std::ostringstream Data;
70 
71  Data.imbue(std::locale::classic());
72  Data.precision(16);
73  Data << number;
74 
75  mData = Data.str();
77 }
class CEvaluationNode::CPrecedence mPrecedence
#define PRECEDENCE_NUMBER
CEvaluationNodeNumber::CEvaluationNodeNumber ( const CEvaluationNodeNumber src)

Copy constructor

Parameters
constCEvaluationNodeNumber & src

Definition at line 79 of file CEvaluationNodeNumber.cpp.

79  :
80  CEvaluationNode(src)
81 {}
CEvaluationNodeNumber::~CEvaluationNodeNumber ( )
virtual

Destructor

Definition at line 83 of file CEvaluationNodeNumber.cpp.

83 {}

Member Function Documentation

CEvaluationNode * CEvaluationNodeNumber::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 86 of file CEvaluationNodeNumber.cpp.

References CEvaluationNodeConstant::_INFINITY, CEvaluationNodeConstant::_NaN, abs, CCopasiNode< _Data >::addChild(), CEvaluationNodeNumber(), DOUBLE, ENOTATION, INTEGER, INVALID, CEvaluationNodeFunction::MINUS, RATIONALE, and CEvaluationNode::subType().

Referenced by CEvaluationTree::fromAST().

87 {
88  assert(pASTNode->getNumChildren() == children.size());
89 
90  std::stringstream ss;
92  std::string data = "";
93  CEvaluationNode* pNode = NULL;
94 
95  switch (pASTNode->getType())
96  {
97  case AST_INTEGER:
98  subType = INTEGER;
99 
100  if (pASTNode->getInteger() < 0)
101  {
103 
104  ss << abs(pASTNode->getInteger());
105  data = ss.str();
106  pNode->addChild(new CEvaluationNodeNumber(subType, data));
107  }
108  else
109  {
110  ss << pASTNode->getInteger();
111  data = ss.str();
112  pNode = new CEvaluationNodeNumber(subType, data);
113  }
114 
115  break;
116 
117  case AST_REAL:
118  subType = DOUBLE;
119 
120  if (pASTNode->getReal() == (std::numeric_limits<C_FLOAT64>::infinity()))
121  {
123  }
124  else if (pASTNode->getReal() == (-std::numeric_limits<C_FLOAT64>::infinity()))
125  {
128  }
129  else if (isnan(pASTNode->getReal()))
130  {
132  }
133  else if (pASTNode->getReal() < 0.0)
134  {
136 
137  ss << fabs(pASTNode->getReal());
138  data = ss.str();
139  pNode->addChild(new CEvaluationNodeNumber(subType, data));
140  }
141  else
142  {
143  ss << pASTNode->getReal();
144  data = ss.str();
145  pNode = new CEvaluationNodeNumber(subType, data);
146  }
147 
148  break;
149 
150  case AST_REAL_E:
151  subType = ENOTATION;
152 
153  if (pASTNode->getReal() == (std::numeric_limits<C_FLOAT64>::infinity()))
154  {
156  }
157  else if (pASTNode->getReal() == (-std::numeric_limits<C_FLOAT64>::infinity()))
158  {
161  }
162  else if (isnan(pASTNode->getReal()))
163  {
165  }
166  else if (pASTNode->getReal() < 0.0)
167  {
169 
170  ss << fabs(pASTNode->getReal());
171  data = ss.str();
172  pNode->addChild(new CEvaluationNodeNumber(subType, data));
173  }
174  else
175  {
176  ss << pASTNode->getReal();
177  data = ss.str();
178  pNode = new CEvaluationNodeNumber(subType, data);
179  }
180 
181  break;
182 
183  case AST_RATIONAL:
184  subType = RATIONALE;
185 
186  if (pASTNode->getReal() < 0.0) // getReal returns the value of the node
187  {
189 
190  ss << "(" << abs(pASTNode->getNumerator()) << "/" << abs(pASTNode->getDenominator()) << ")";
191  data = ss.str();
192  pNode->addChild(new CEvaluationNodeNumber(subType, data));
193  }
194  else
195  {
196  ss << "(" << pASTNode->getNumerator() << "/" << pASTNode->getDenominator() << ")";
197  data = ss.str();
198  pNode = new CEvaluationNodeNumber(subType, data);
199  }
200 
201  break;
202 
203  default:
204  subType = INVALID;
205  break;
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)
#define abs(x)
Definition: f2c.h:173
std::string CEvaluationNodeNumber::getCCodeString ( const std::vector< std::string > &  children) const
virtual

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

Returns
string representing a double value

Reimplemented from CEvaluationNode.

Definition at line 270 of file CEvaluationNodeNumber.cpp.

References CEvaluationNode::getValue().

271 {
272  std::ostringstream out;
273  out << std::setprecision(std::numeric_limits<double>::digits10 + 2) << std::fixed << getValue();
274  return out.str();
275 }
const C_FLOAT64 & getValue() const
std::string CEvaluationNodeNumber::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 258 of file CEvaluationNodeNumber.cpp.

References CCopasiNode< std::string >::mData.

261 {
262  std::ostringstream out;
263 
264  //or use mValue instead?
265  out << "<mn>" << mData << "</mn>" << std::endl;
266 
267  return out.str();
268 }
ASTNode * CEvaluationNodeNumber::toAST ( const CCopasiDataModel pDataModel) const
virtual

Create a new ASTNode corresponding to this NumberNode.

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

Reimplemented from CEvaluationNode.

Definition at line 211 of file CEvaluationNodeNumber.cpp.

References DOUBLE, ENOTATION, CEvaluationNode::getType(), CEvaluationNode::getValue(), INTEGER, INVALID, CCopasiNode< std::string >::mData, RATIONALE, strToDouble(), and CEvaluationNode::subType().

212 {
214  ASTNode* node = new ASTNode();
215  double num1;
216  double num2;
217  const char * end;
218  const char * str = mData.c_str();
219 
220  switch (subType)
221  {
222  case DOUBLE:
223  node->setType(AST_REAL);
224  node->setValue(this->getValue());
225  break;
226 
227  case INTEGER:
228  node->setType(AST_INTEGER);
229  node->setValue((long)this->getValue());
230  break;
231 
232  case ENOTATION:
233  node->setType(AST_REAL_E);
234  num2 = floor(log10(this->getValue()));
235  num1 = pow(10.0, log10(this->getValue()) - num2);
236  node->setValue(num1, (long)num2);
237  break;
238 
239  case RATIONALE:
240  node->setType(AST_RATIONAL);
241  str++; // Skip the '('
242  num1 = strToDouble(str, &end);
243  end++; // Skip the '/'
244  num2 = strToDouble(end, NULL);
245  node->setValue((long)num1, (long)num2);
246  break;
247 
248  case INVALID:
249  break;
250  }
251 
252  return node;
253 }
const C_FLOAT64 & getValue() const
const Type & getType() const
static Type subType(const Type &type)
double strToDouble(const char *str, char const **pTail)
Definition: utility.cpp:325

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