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

#include <CEvaluationNodeCall.h>

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

Public Types

enum  SubType { INVALID = 0x00FFFFFF, FUNCTION = 0x00000000, EXPRESSION = 0x00000001 }
 
- 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 bool addChild (CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
 
virtual void calculate ()
 
bool calls (std::set< std::string > &list) const
 
 CEvaluationNodeCall (const SubType &subType, const Data &data)
 
 CEvaluationNodeCall (const CEvaluationNodeCall &src)
 
virtual bool compile (const CEvaluationTree *pTree)
 
virtual std::string getBerkeleyMadonnaString (const std::vector< std::string > &children) const
 
const CEvaluationTreegetCalledTree () const
 
virtual std::string getCCodeString (const std::vector< std::string > &children) const
 
virtual const DatagetData () const
 
virtual std::string getDisplayString (const std::vector< std::string > &children) const
 
virtual std::string getInfix (const std::vector< std::string > &children) const
 
const std::vector
< CEvaluationNode * > 
getListOfChildNodes () 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
 
const bool & isBooleanRequired () const
 
virtual bool removeChild (CCopasiNode< Data > *pChild)
 
void setBooleanRequired (const bool &booleanRequired)
 
virtual bool setData (const Data &data)
 
virtual ASTNode * toAST (const CCopasiDataModel *pDataModel) const
 
virtual ~CEvaluationNodeCall ()
 
- 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 >
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
 
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 ~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

 CEvaluationNodeCall ()
 

Static Private Member Functions

static CCallParameters
< C_FLOAT64 > * 
buildParameters (const std::vector< CEvaluationNode * > &vector)
 
static void clearParameters (CCallParameters< C_FLOAT64 > *pCallParameters, const std::vector< CEvaluationNode * > &vector)
 
static bool verifyParameters (const std::vector< CEvaluationNode * > &vector, const CFunctionParameters &functionParameters)
 

Private Attributes

bool mBooleanRequired
 
std::vector< CEvaluationNode * > mCallNodes
 
CCallParameters< C_FLOAT64 > * mpCallParameters
 
CExpressionmpExpression
 
CFunctionmpFunction
 
bool mQuotesRequired
 
CRegisteredObjectName mRegisteredFunctionCN
 

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 30 of file CEvaluationNodeCall.h.

Member Enumeration Documentation

Enumeration of possible node types.

Enumerator
INVALID 
FUNCTION 
EXPRESSION 

Definition at line 36 of file CEvaluationNodeCall.h.

Constructor & Destructor Documentation

CEvaluationNodeCall::CEvaluationNodeCall ( )
private

Default constructor

Definition at line 28 of file CEvaluationNodeCall.cpp.

References CEvaluationNode::mPrecedence, and PRECEDENCE_NUMBER.

Referenced by fromAST().

28  :
30  mpFunction(NULL),
31  mpExpression(NULL),
32  mCallNodes(),
33  mpCallParameters(NULL),
34  mQuotesRequired(false),
35  mBooleanRequired(false),
CCallParameters< C_FLOAT64 > * mpCallParameters
class CEvaluationNode::CPrecedence mPrecedence
#define PRECEDENCE_NUMBER
CRegisteredObjectName mRegisteredFunctionCN
std::vector< CEvaluationNode * > mCallNodes
CEvaluationNodeCall::CEvaluationNodeCall ( const SubType subType,
const Data data 
)

Default constructor

Parameters
constSubType & subType
constData & data

Definition at line 39 of file CEvaluationNodeCall.cpp.

References EXPRESSION, fatalError, FUNCTION, CEvaluationNode::isKeyword(), CCopasiNode< std::string >::mData, CEvaluationNode::mPrecedence, mQuotesRequired, PRECEDENCE_FUNCTION, quote(), setData(), and unQuote().

40  :
42  mpFunction(NULL),
43  mpExpression(NULL),
44  mCallNodes(),
45  mpCallParameters(NULL),
46  mQuotesRequired(false),
47  mBooleanRequired(false),
49 {
50  setData(data);
51  mData = unQuote(mData);
52 
53  // We force quoting if the round trip unquote, quote does not recover the original input
54  if (isKeyword(mData))
55  {
56  mQuotesRequired = true;
57  }
58 
59  if (mData != data && quote(mData) != data)
60  {
61  mQuotesRequired = true;
62  }
63 
64  switch (subType)
65  {
66  case FUNCTION:
67  case EXPRESSION:
68  break;
69 
70  default:
71  fatalError();
72  break;
73  }
74 
76 }
std::string unQuote(const std::string &name)
Definition: utility.cpp:120
#define fatalError()
static bool isKeyword(const std::string &str)
#define PRECEDENCE_FUNCTION
CCallParameters< C_FLOAT64 > * mpCallParameters
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
virtual bool setData(const Data &data)
static Type subType(const Type &type)
class CEvaluationNode::CPrecedence mPrecedence
CRegisteredObjectName mRegisteredFunctionCN
std::vector< CEvaluationNode * > mCallNodes
CEvaluationNodeCall::CEvaluationNodeCall ( const CEvaluationNodeCall src)

Copy constructor

Parameters
constCEvaluationNodeCall & src

Definition at line 78 of file CEvaluationNodeCall.cpp.

References buildParameters(), mCallNodes, and mpCallParameters.

78  :
79  CEvaluationNode(src),
83  mpCallParameters(NULL),
static CCallParameters< C_FLOAT64 > * buildParameters(const std::vector< CEvaluationNode * > &vector)
CCallParameters< C_FLOAT64 > * mpCallParameters
CRegisteredObjectName mRegisteredFunctionCN
std::vector< CEvaluationNode * > mCallNodes
CEvaluationNodeCall::~CEvaluationNodeCall ( )
virtual

Destructor

Definition at line 89 of file CEvaluationNodeCall.cpp.

89 {}

Member Function Documentation

bool CEvaluationNodeCall::addChild ( CCopasiNode< Data > *  pChild,
CCopasiNode< Data > *  pAfter = NULL 
)
virtual

Add a child to a node. If pAfter == this the child will be inserted at the front of the list of children.

Parameters
CCopasiNode<Data > * pChild
CCopasiNode<Data > * pAfter (default: NULL appended to the list of children)
Returns
bool Success

Reimplemented from CCopasiNode< std::string >.

Definition at line 465 of file CEvaluationNodeCall.cpp.

References CCopasiNode< _Data >::addChild(), and mCallNodes.

Referenced by SBMLImporter::createCReactionFromReaction(), CSBMLExporter::createKineticExpression(), CEvaluationNodeNormalizer::normalizeCEvaluationNodeCall(), and test_compare_utilities::test_copasi_function_expansion().

467 {
468  CCopasiNode< Data >::addChild(pChild, pAfter);
469 
470  if (pAfter == NULL)
471  {
472  mCallNodes.push_back(static_cast<CEvaluationNode *>(pChild));
473  return true;
474  }
475 
476  std::vector<CEvaluationNode *>::iterator it = mCallNodes.begin();
477 
478  if (pAfter != this)
479  {
480  std::vector<CEvaluationNode *>::iterator end = mCallNodes.end();
481 
482  while (it != end && *it != pAfter) ++it;
483  }
484 
485  mCallNodes.insert(it, static_cast<CEvaluationNode *>(pChild));
486 
487  return true;
488 }
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
std::vector< CEvaluationNode * > mCallNodes
CCallParameters< C_FLOAT64 > * CEvaluationNodeCall::buildParameters ( const std::vector< CEvaluationNode * > &  vector)
staticprivate

Build the list of call parameters which correspond to the list of call nodes.

Definition at line 503 of file CEvaluationNodeCall.cpp.

References CEvaluationNode::type(), and CEvaluationNode::VECTOR.

Referenced by CEvaluationNodeCall(), and compile().

504 {
505  std::vector<CEvaluationNode *>::const_iterator it = vector.begin();
506  std::vector<CEvaluationNode *>::const_iterator end = vector.end();
507 
508  CCallParameters< C_FLOAT64 > * pCallParameters =
509  new CCallParameters< C_FLOAT64 >(vector.size());
510  size_t i;
511 
512  for (i = 0; it != end; ++it, i++)
513  {
514  if (type((*it)->getType()) == CEvaluationNode::VECTOR)
515  (*pCallParameters)[i].vector = buildParameters(static_cast<const CEvaluationNodeVector *>(*it)->getVector());
516  else
517  (*pCallParameters)[i].value = (*it)->getValuePointer();
518  }
519 
520  return pCallParameters;
521 }
static CCallParameters< C_FLOAT64 > * buildParameters(const std::vector< CEvaluationNode * > &vector)
static Type type(const Type &type)
void CEvaluationNodeCall::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 91 of file CEvaluationNodeCall.cpp.

References CExpression::calcValue(), CFunction::calcValue(), EXPRESSION, FUNCTION, mpCallParameters, mpExpression, mpFunction, CEvaluationNode::mType, and CEvaluationNode::mValue.

92 {
93  switch (mType & 0x00FFFFFF)
94  {
95  case FUNCTION:
97  break;
98 
99  case EXPRESSION:
101  break;
102 
103  default:
104  mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
105  break;
106  }
107 }
virtual const C_FLOAT64 & calcValue()
CCallParameters< C_FLOAT64 > * mpCallParameters
virtual const C_FLOAT64 & calcValue(const CCallParameters< C_FLOAT64 > &callParameters)
Definition: CFunction.cpp:159
bool CEvaluationNodeCall::calls ( std::set< std::string > &  list) const

Check whether node the calls any tree in the list

Parameters
std::set<std::string > & list
Returns
bool calls

Definition at line 196 of file CEvaluationNodeCall.cpp.

References CEvaluationTree::calls(), CFunctionDB::findFunction(), CCopasiRootContainer::getFunctionList(), and CCopasiNode< std::string >::mData.

197 {
198  if (list.count(mData)) return true;
199 
200  CEvaluationTree * pTree =
202 
203  if (pTree) return pTree->calls(list);
204 
205  return false;
206 }
static CFunctionDB * getFunctionList()
bool calls(std::set< std::string > &list) const
CFunction * findFunction(const std::string &functionName)
void CEvaluationNodeCall::clearParameters ( CCallParameters< C_FLOAT64 > *  pCallParameters,
const std::vector< CEvaluationNode * > &  vector 
)
staticprivate

Clear the list of call parameters.

Definition at line 524 of file CEvaluationNodeCall.cpp.

References CEvaluationNode::type(), and CEvaluationNode::VECTOR.

Referenced by compile().

526 {
527  if (!pCallParameters) return;
528 
529  std::vector<CEvaluationNode *>::const_iterator it = vector.begin();
530  std::vector<CEvaluationNode *>::const_iterator end = vector.end();
531 
532  size_t i;
533 
534  for (i = 0; it != end; ++it, i++)
535  {
536  if (type((*it)->getType()) == CEvaluationNode::VECTOR)
537  clearParameters((*pCallParameters)[i].vector,
538  static_cast<const CEvaluationNodeVector *>(*it)->getVector());
539  }
540 
541  delete pCallParameters;
542  return;
543 }
static void clearParameters(CCallParameters< C_FLOAT64 > *pCallParameters, const std::vector< CEvaluationNode * > &vector)
static Type type(const Type &type)
bool CEvaluationNodeCall::compile ( const CEvaluationTree pTree)
virtual

Compile a node;

Parameters
constCEvaluationTree * pTree
Returns
bool success;

Reimplemented from CEvaluationNode.

Definition at line 109 of file CEvaluationNodeCall.cpp.

References buildParameters(), CEvaluationNode::CALL, clearParameters(), CExpression::compile(), EXPRESSION, CFunctionDB::findFunction(), FUNCTION, CCopasiObject::getCN(), CCopasiRootContainer::getFunctionList(), CCopasiContainer::getObject(), CCopasiRootContainer::getRoot(), CFunction::getVariables(), mCallNodes, CCopasiNode< std::string >::mData, mpCallParameters, mpExpression, mpFunction, mRegisteredFunctionCN, CEvaluationNode::mType, and verifyParameters().

110 {
111  bool success = true;
113 
114  CObjectInterface * pObjectInterface = NULL;
115 
116  if (mRegisteredFunctionCN != "")
117  {
118  pObjectInterface = const_cast< CObjectInterface * >(CCopasiRootContainer::getRoot()->getObject(mRegisteredFunctionCN));
119  }
120 
121  switch (mType & 0x00FFFFFF)
122  {
123  case FUNCTION:
124 
125  if (pObjectInterface != NULL)
126  {
127  mpFunction = dynamic_cast< CFunction * >(pObjectInterface);
128  }
129  else
130  {
131  mpFunction =
133  }
134 
135  if (!mpFunction) return false;
136 
138 
139  // We need to check whether the provided arguments match the on needed by the
140  // function;
141  if (!verifyParameters(mCallNodes, mpFunction->getVariables())) return false;
142 
144  break;
145 
146  case EXPRESSION:
147 
148  if (pObjectInterface != NULL)
149  {
150  mpExpression = dynamic_cast<CExpression *>(pObjectInterface);
151  }
152  else
153  {
154  mpExpression =
156  }
157 
158  if (!mpExpression)
159  {
160  // We may have a function with no arguments the parser is not able to distinguish
161  // between that and an expression.
162  if (pObjectInterface != NULL)
163  {
164  mpFunction = dynamic_cast< CFunction * >(pObjectInterface);
165  }
166  else
167  {
168  mpFunction =
170  }
171 
172  if (!mpFunction) return false;
173 
175 
177  success = compile(pTree);
178  }
179  else
180  {
182 
183  success = mpExpression->compile(static_cast<const CExpression *>(pTree)->getListOfContainer());
184  }
185 
186  break;
187 
188  default:
189  success = false;
190  break;
191  }
192 
193  return success;
194 }
static void clearParameters(CCallParameters< C_FLOAT64 > *pCallParameters, const std::vector< CEvaluationNode * > &vector)
static bool verifyParameters(const std::vector< CEvaluationNode * > &vector, const CFunctionParameters &functionParameters)
virtual CCopasiObjectName getCN() const
static CCallParameters< C_FLOAT64 > * buildParameters(const std::vector< CEvaluationNode * > &vector)
virtual bool compile(const CEvaluationTree *pTree)
virtual bool compile(std::vector< CCopasiContainer * > listOfContainer=CCopasiContainer::EmptyList)
Definition: CExpression.cpp:97
CCallParameters< C_FLOAT64 > * mpCallParameters
static CFunctionDB * getFunctionList()
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
static const CCopasiContainer * getRoot()
CFunction * findFunction(const std::string &functionName)
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
CRegisteredObjectName mRegisteredFunctionCN
std::vector< CEvaluationNode * > mCallNodes
CEvaluationNode * CEvaluationNodeCall::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 427 of file CEvaluationNodeCall.cpp.

References CEvaluationNode::addChildren(), CEvaluationNodeCall(), FUNCTION, and CEvaluationNode::subType().

Referenced by CEvaluationTree::fromAST().

428 {
429  assert(pASTNode->getNumChildren() == children.size());
430 
432  std::string data = pASTNode->getName();
433 
434  CEvaluationNodeCall * pNode = new CEvaluationNodeCall(subType, data);
435 
436  pNode->addChildren(children);
437 
438  return pNode;
439 }
void addChildren(const std::vector< CEvaluationNode * > &children)
static Type subType(const Type &type)
std::string CEvaluationNodeCall::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 393 of file CEvaluationNodeCall.cpp.

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

394 {
395  std::string DisplayString;
396 
397  if (mQuotesRequired)
398  {
399  DisplayString = "\"" + quote(mData, "-+^*/%(){},\t\r\n\"") + "\"(";
400  }
401  else
402  {
403  DisplayString = quote(mData, "-+^*/%(){},\t\r\n") + "(";
404  }
405 
406  return DisplayString;
407 }
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
const CEvaluationTree * CEvaluationNodeCall::getCalledTree ( ) const
std::string CEvaluationNodeCall::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 345 of file CEvaluationNodeCall.cpp.

References EXPRESSION, FUNCTION, getData(), CCopasiNode< std::string >::mData, mQuotesRequired, CEvaluationNode::mType, and quote().

346 {
347  std::string DisplayString;
348 
349  std::string Data;
350 
351  if (mData.empty())
352  Data = getData();
353  else
354  Data = mData;
355 
356  if (mQuotesRequired)
357  {
358  DisplayString = "\"" + quote(Data, "-+^*/%(){},\t\r\n\"") + "\"(";
359  }
360  else
361  {
362  DisplayString = quote(Data, "-+^*/%(){},\t\r\n") + "(";
363  }
364 
365  switch (mType & 0x00FFFFFF)
366  {
367  case FUNCTION:
368  {
369 
370  std::vector< std::string >::const_iterator it = children.begin();
371  std::vector< std::string >::const_iterator end = children.end();
372 
373  if (it != end) DisplayString += *it++;
374 
375  for (; it != end; ++it)
376  DisplayString += "," + *it;
377  }
378 
379  break;
380 
381  case EXPRESSION:
382  break;
383 
384  default:
385  return "@";
386  break;
387  }
388 
389  return DisplayString + ")";
390 }
virtual const Data & getData() const
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
const CEvaluationNode::Data & CEvaluationNodeCall::getData ( ) const
virtual

Retrieve the value of the node.

Returns
const Data & value

Reimplemented from CCopasiNode< std::string >.

Definition at line 209 of file CEvaluationNodeCall.cpp.

References CCopasiObject::getObjectName(), CEvaluationNode::isKeyword(), CCopasiNode< std::string >::mData, mpExpression, mpFunction, mQuotesRequired, quote(), and unQuote().

Referenced by expand_function_call(), getCCodeString(), getInfix(), getMMLString(), CEvaluationNodeNormalizer::normalizeCEvaluationNodeCall(), test000043::test_hasOnlySubstanceUnits(), test000042::test_hasOnlySubstanceUnits(), test000075::test_import_time_dependent_function_definition(), test000078::test_l2v4_import_unordered_functions(), and toAST().

210 {
211  // We determine whether quoting is required here since we can not be sure
212  // that the original infix is correct.
213 
214  std::string Data;
215 
216  if (isKeyword(mData))
217  {
218  mQuotesRequired = true;
219  }
220 
221  if (mpFunction != NULL)
222  {
223  Data = mpFunction->getObjectName();
225 
226  return mpFunction->getObjectName();
227  }
228 
229  if (mpExpression != NULL)
230  {
231  Data = mpExpression->getObjectName();
233 
234  return mpExpression->getObjectName();
235  }
236 
237  return mData;
238 }
std::string unQuote(const std::string &name)
Definition: utility.cpp:120
const std::string & getObjectName() const
static bool isKeyword(const std::string &str)
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
std::string CEvaluationNodeCall::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 305 of file CEvaluationNodeCall.cpp.

References EXPRESSION, FUNCTION, CCopasiNode< std::string >::mData, mQuotesRequired, CEvaluationNode::mType, and quote().

306 {
307  std::string DisplayString;
308 
309  if (mQuotesRequired)
310  {
311  DisplayString = "\"" + quote(mData, "-+^*/%(){},\t\r\n\"") + "\"(";
312  }
313  else
314  {
315  DisplayString = quote(mData, "-+^*/%(){},\t\r\n") + "(";
316  }
317 
318  switch (mType & 0x00FFFFFF)
319  {
320  case FUNCTION:
321  {
322  std::vector< std::string >::const_iterator it = children.begin();
323  std::vector< std::string >::const_iterator end = children.end();
324 
325  if (it != end) DisplayString += *it++;
326 
327  for (; it != end; ++it)
328  DisplayString += "," + *it;
329  }
330 
331  break;
332 
333  case EXPRESSION:
334  break;
335 
336  default:
337  return "@";
338  break;
339  }
340 
341  return DisplayString + ")";
342 }
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
std::string CEvaluationNodeCall::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 262 of file CEvaluationNodeCall.cpp.

References EXPRESSION, FUNCTION, getData(), mQuotesRequired, CEvaluationNode::mType, and quote().

263 {
264  std::string Infix;
265 
266  //We use getData instead of mData since getData also detects whether quoting is needed.
267  const std::string & Data = getData();
268 
269  if (mQuotesRequired)
270  {
271  Infix = "\"" + quote(Data, "-+^*/%(){},\t\r\n\"") + "\"(";
272  }
273  else
274  {
275  Infix = quote(Data, "-+^*/%(){},\t\r\n") + "(";
276  }
277 
278  switch (mType & 0x00FFFFFF)
279  {
280  case FUNCTION:
281  {
282  std::vector< std::string >::const_iterator it = children.begin();
283  std::vector< std::string>::const_iterator end = children.end();
284 
285  if (it != end) Infix += *it++;
286 
287  for (; it != end; ++it)
288  Infix += "," + *it;
289  }
290 
291  break;
292 
293  case EXPRESSION:
294  break;
295 
296  default:
297  return "@";
298  break;
299  }
300 
301  return Infix + ")";
302 }
virtual const Data & getData() const
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
const std::vector<CEvaluationNode *> CEvaluationNodeCall::getListOfChildNodes ( ) const
inline

returns the vector of child nodes, corresponding to the arguments of a function call

Definition at line 188 of file CEvaluationNodeCall.h.

References mCallNodes.

Referenced by CFunctionAnalyzer::evaluateNode(), and CEvaluationNodeNormalizer::normalizeCEvaluationNodeCall().

188 {return mCallNodes;}
std::vector< CEvaluationNode * > mCallNodes
std::string CEvaluationNodeCall::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 583 of file CEvaluationNodeCall.cpp.

References EXPRESSION, CMathMl::fixName(), FUNCTION, getData(), mpFunction, mQuotesRequired, CEvaluationNode::mType, quote(), and CFunction::writeMathML().

586 {
587  std::ostringstream out;
588 
589  std::vector< std::string >::const_iterator it = children.begin();
590  std::vector< std::string >::const_iterator end = children.end();
591 
592  switch (mType & 0x00FFFFFF)
593  {
594  case FUNCTION:
595  {
596 
597  if (!expand || !mpFunction)
598  {
599  out << "<mrow>" << std::endl;
600 
601  std::string Data = getData();
602 
603  if (mQuotesRequired)
604  {
605  Data = "\"" + quote(Data, "-+^*/%(){},\t\r\n\"") + "\"";
606  }
607 
608  out << "<mi>" << CMathMl::fixName(Data) << "</mi>" << std::endl;
609  out << "<mrow>" << std::endl;
610  out << "<mo>(</mo>" << std::endl;
611  out << "<mrow>" << std::endl;
612 
613  if (it != end)
614  {
615  out << *it++;
616  }
617 
618  for (; it != end; ++it)
619  {
620  out << "<mo> , </mo>" << std::endl;
621  out << *it;
622  }
623 
624  out << "</mrow>" << std::endl;
625  out << "<mo>) </mo>" << std::endl;
626 
627  out << "</mrow>" << std::endl;
628  out << "</mrow>" << std::endl;
629  }
630  else
631  {
632  std::vector< std::vector< std::string > > Variables;
633 
634  for (; it != end; ++it)
635  {
636  std::vector< std::string > Variable;
637  Variable.push_back(*it);
638  Variables.push_back(Variable);
639  }
640 
641  out << "<mfenced>" << std::endl;
642  out << mpFunction->writeMathML(Variables, expand, expand);
643  out << "</mfenced>" << std::endl;
644  }
645  }
646  break;
647 
648  case EXPRESSION:
649  break;
650 
651  default:
652  break;
653  }
654 
655  return out.str();
656 }
static std::string fixName(const std::string &name)
Definition: copasimathml.h:33
virtual const Data & getData() const
virtual void writeMathML(std::ostream &out, size_t l=0) const
Definition: CFunction.cpp:389
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
std::string CEvaluationNodeCall::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 410 of file CEvaluationNodeCall.cpp.

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

411 {
412  std::string DisplayString;
413 
414  if (mQuotesRequired)
415  {
416  DisplayString = "\"" + quote(mData, "-+^*/%(){},\t\r\n\"") + "\"(";
417  }
418  else
419  {
420  DisplayString = quote(mData, "-+^*/%(){},\t\r\n") + "(";
421  }
422 
423  return DisplayString;
424 }
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
bool CEvaluationNodeCall::isBoolean ( ) const
virtual

Check whether the result is Boolean

Returns
bool isBoolean

Reimplemented from CEvaluationNode.

Definition at line 665 of file CEvaluationNodeCall.cpp.

References getCalledTree(), and CEvaluationTree::isBoolean().

666 {
667  const CEvaluationTree * pEvaluationTree = getCalledTree();
668 
669  if (pEvaluationTree != NULL)
670  {
671  return pEvaluationTree->isBoolean();
672  }
673 
674  return false;
675 }
const CEvaluationTree * getCalledTree() const
bool isBoolean() const
const bool & CEvaluationNodeCall::isBooleanRequired ( ) const

Check whether the result must be Boolean

Returns
const bool & isBooleanRequired

Definition at line 661 of file CEvaluationNodeCall.cpp.

References mBooleanRequired.

bool CEvaluationNodeCall::removeChild ( CCopasiNode< Data > *  pChild)
virtual

Remove a child from a node.

Parameters
CCopasiNode<Data > * pChild
Returns
bool Success

Reimplemented from CCopasiNode< std::string >.

Definition at line 490 of file CEvaluationNodeCall.cpp.

References mCallNodes, and CCopasiNode< _Data >::removeChild().

Referenced by CEvaluationNodeNormalizer::normalizeCEvaluationNodeCall().

491 {
492  std::vector<CEvaluationNode *>::iterator it = mCallNodes.begin();
493  std::vector<CEvaluationNode *>::iterator end = mCallNodes.end();
494 
495  while (it != end && *it != pChild) ++it;
496 
497  if (it != end) mCallNodes.erase(it);
498 
499  return CCopasiNode< Data >::removeChild(pChild);
500 }
virtual bool removeChild(CCopasiNode< Data > *pChild)
Definition: CCopasiNode.h:181
std::vector< CEvaluationNode * > mCallNodes
void CEvaluationNodeCall::setBooleanRequired ( const bool &  booleanRequired)

Set whether the result of the node must be Boolean

Parameters
constbool & booleanRequired

Definition at line 658 of file CEvaluationNodeCall.cpp.

References mBooleanRequired.

659 {mBooleanRequired = booleanRequired;}
bool CEvaluationNodeCall::setData ( const Data data)
virtual

Set the data of the Node.

Parameters
constData & data
Returns
bool success

Reimplemented from CCopasiNode< std::string >.

Definition at line 241 of file CEvaluationNodeCall.cpp.

References CEvaluationNode::isKeyword(), CCopasiNode< std::string >::mData, mQuotesRequired, mRegisteredFunctionCN, quote(), and unQuote().

Referenced by CEvaluationNodeCall().

242 {
243  mData = unQuote(data);
244 
245  // We force quoting if the round trip unquote, quote does not recover the original input
246  if (isKeyword(mData))
247  {
248  mQuotesRequired = true;
249  }
250 
251  if (mData != data && quote(mData) != data)
252  {
253  mQuotesRequired = true;
254  }
255 
256  mRegisteredFunctionCN = std::string("");
257 
258  return true;
259 }
std::string unQuote(const std::string &name)
Definition: utility.cpp:120
static bool isKeyword(const std::string &str)
std::string quote(const std::string &name, const std::string &additionalEscapes)
Definition: utility.cpp:144
CRegisteredObjectName mRegisteredFunctionCN
ASTNode * CEvaluationNodeCall::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 441 of file CEvaluationNodeCall.cpp.

References CCopasiNode< _Data >::addChild(), fatalError, CFunctionDB::findFunction(), CCopasiNode< std::string >::getChild(), getData(), CCopasiRootContainer::getFunctionList(), CFunction::getSBMLId(), CCopasiNode< _Data >::getSibling(), and CEvaluationNode::toAST().

442 {
443  ASTNode* pNode = NULL;
444 
445  pNode = new ASTNode(AST_FUNCTION);
446  const std::string funName = this->getData();
448  assert(pFun != NULL);
449 
450  if (pFun == NULL || pFun->getSBMLId().empty()) fatalError();
451 
452  pNode->setName(pFun->getSBMLId().c_str());
453 
454  const CEvaluationNode* child = static_cast<const CEvaluationNode*>(this->getChild());
455 
456  while (child)
457  {
458  pNode->addChild(child->toAST(pDataModel));
459  child = static_cast<const CEvaluationNode*>(child->getSibling());
460  }
461 
462  return pNode;
463 }
virtual ASTNode * toAST(const CCopasiDataModel *pDataModel) const
CCopasiNode< Data > * getSibling()
Definition: CCopasiNode.h:353
#define fatalError()
virtual const Data & getData() const
virtual bool addChild(CCopasiNode< Data > *pChild, CCopasiNode< Data > *pAfter=NULL)
Definition: CCopasiNode.h:156
static CFunctionDB * getFunctionList()
const std::string & getSBMLId() const
Definition: CFunction.cpp:68
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
CCopasiNode< Data > * getChild()
Definition: CCopasiNode.h:210
CFunction * findFunction(const std::string &functionName)
bool CEvaluationNodeCall::verifyParameters ( const std::vector< CEvaluationNode * > &  vector,
const CFunctionParameters functionParameters 
)
staticprivate

Verifies that the parameters match the function parameters.

Parameters
conststd::vector<CEvaluationNode *> & vector
constCFunctionParameters & functionParameters
Returns
bool verified

Definition at line 546 of file CEvaluationNodeCall.cpp.

References CEvaluationNode::getType(), CFunctionParameters::size(), CEvaluationNode::type(), CEvaluationNode::VECTOR, and CFunctionParameter::VFLOAT64.

Referenced by compile().

548 {
549  if (vector.size() != functionParameters.size()) return false;
550 
551  std::vector<CEvaluationNode *>::const_iterator it = vector.begin();
552  std::vector<CEvaluationNode *>::const_iterator end = vector.end();
553 
554  size_t i;
555 
556  for (i = 0; it != end; ++it, i++)
557  {
558  if ((type((*it)->getType()) == CEvaluationNode::VECTOR &&
559  functionParameters[i]->getType() != CFunctionParameter::VFLOAT64) ||
560  functionParameters[i]->getType() == CFunctionParameter::VFLOAT64)
561  return false;
562  }
563 
564  return true;
565 }
const Type & getType() const
static Type type(const Type &type)

Member Data Documentation

bool CEvaluationNodeCall::mBooleanRequired
private

Definition at line 240 of file CEvaluationNodeCall.h.

Referenced by isBooleanRequired(), and setBooleanRequired().

std::vector<CEvaluationNode *> CEvaluationNodeCall::mCallNodes
private
CCallParameters< C_FLOAT64 >* CEvaluationNodeCall::mpCallParameters
private

Definition at line 238 of file CEvaluationNodeCall.h.

Referenced by calculate(), CEvaluationNodeCall(), and compile().

CExpression* CEvaluationNodeCall::mpExpression
private

Definition at line 236 of file CEvaluationNodeCall.h.

Referenced by calculate(), compile(), and getData().

CFunction* CEvaluationNodeCall::mpFunction
private

Definition at line 235 of file CEvaluationNodeCall.h.

Referenced by calculate(), compile(), getData(), and getMMLString().

bool CEvaluationNodeCall::mQuotesRequired
mutableprivate
CRegisteredObjectName CEvaluationNodeCall::mRegisteredFunctionCN
private

The registered object name to track eventual renaming.

Definition at line 245 of file CEvaluationNodeCall.h.

Referenced by compile(), and setData().


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