17 #include "sbml/util/List.h"
18 #include "sbml/common/libsbml-config-common.h"
22 #ifndef LIBSBML_USE_LEGACY_MATH
45 else if (mFunction != NULL)
47 unsigned int size = mFunction->getNumChildren();
49 for (
unsigned int i = mFunction->getNumChildren(); i > 0; i--)
51 mFunction->removeChild(i - 1);
54 for (
unsigned int i = 0; i < children->getSize(); i++)
56 mFunction->addChild(static_cast<ASTNode*>(children->get(i)));
66 if (this->getType() == AST_RATIONAL)
68 setValue(templ.getNumerator(), templ.getDenominator());
70 else if (this->getType() == AST_REAL)
72 setValue(templ.getReal());
74 else if (this->getType() == AST_REAL_E)
76 setValue(templ.getMantissa(), templ.getExponent());
79 if (this->getType() == AST_PLUS ||
80 this->getType() == AST_MINUS ||
81 this->getType() == AST_TIMES ||
82 this->getType() == AST_DIVIDE ||
83 this->getType() == AST_POWER)
85 this->mChar = templ.getCharacter();
87 else if (this->getType() == AST_INTEGER)
89 setValue(templ.getInteger());
92 if ((!this->isOperator()) && (!this->
isNumber()) && !isConstant())
94 this->setName(templ.getName());
99 for (counter = 0; counter < templ.getNumChildren(); counter++)
120 void ConverterASTNode::printASTNode(
const ASTNode* node,
unsigned int indent)
122 std::string spacer =
"";
123 unsigned int counter;
125 for (counter = 0; counter < indent; counter++)
132 if (node->isFunction() || node->isName())
134 if (node->getName() == NULL)
135 std::cout <<
"emptyName";
137 std::cout << node->getName();
139 else if (node->isOperator())
141 std::cout << node->getCharacter();
143 else if (node->isInteger())
145 std::cout << node->getInteger();
147 else if (node->isReal())
149 std::cout << node->getReal();
153 std::cout <<
"[" << node->getType() <<
"]";
156 std::cout << std::endl;
158 for (counter = 0; counter < node->getNumChildren(); counter++)
160 ConverterASTNode::printASTNode(node->getChild(counter), indent + 2);
163 #endif // COPASI_DEBUG
167 ASTNode * removedChild = getChild(index);
169 this->ASTNode::removeChild(index);
181 while (pTmp->getNumChildren() > 0)
186 ASTNode* pCopy = pTmp->deepCopy();
210 this->mChildren = children;
213 void fixNaryRelational(ASTNode& node)
215 if (!node.isRelational())
return;
217 if (node.getNumChildren() == 2)
return;
219 ASTNodeType_t type = node.getType();
220 std::vector<ASTNode*> nodes;
221 node.setType(AST_LOGICAL_AND);
223 for (
int i = 1; i < node.getNumChildren(); ++i)
225 ASTNode *current =
new ASTNode(type);
226 current->addChild(node.getChild(i - 1)->deepCopy());
227 current->addChild(node.getChild(i)->deepCopy());
228 nodes.push_back(current);
231 while (node.getNumChildren() > 0)
233 delete node.getChild(0);
237 std::vector<ASTNode*>::iterator it = nodes.begin();
239 while (it != nodes.end())
251 if (this->getType() == AST_RATIONAL)
253 this->mDenominator = templ.getDenominator();
254 this->mInteger = templ.getNumerator();
256 else if (this->getType() == AST_REAL || this->getType() == AST_REAL_E)
258 this->mExponent = templ.getExponent();
259 this->mReal = templ.getMantissa();
262 if (templ.getNumChildren() > 2 && (
263 this->getType() == AST_RELATIONAL_EQ ||
264 this->getType() == AST_RELATIONAL_NEQ ||
265 this->getType() == AST_RELATIONAL_GEQ ||
266 this->getType() == AST_RELATIONAL_GT ||
267 this->getType() == AST_RELATIONAL_LEQ ||
268 this->getType() == AST_RELATIONAL_LT))
272 fixNaryRelational(const_cast<ASTNode&>(templ));
273 ASTNode::setType(AST_LOGICAL_AND);
276 if (this->getType() == AST_PLUS || this->getType() == AST_MINUS || this->getType() == AST_TIMES || this->getType() == AST_DIVIDE || this->getType() == AST_POWER)
278 this->mChar = templ.getCharacter();
280 else if (this->getType() == AST_INTEGER)
282 this->mInteger = templ.getInteger();
285 if ((!this->isOperator()) && (!this->
isNumber()))
287 this->setName(templ.getName());
290 unsigned int counter;
292 for (counter = 0; counter < templ.getNumChildren(); counter++)
313 void ConverterASTNode::printASTNode(
const ASTNode* node,
unsigned int indent)
315 std::string spacer =
"";
316 unsigned int counter;
318 for (counter = 0; counter < indent; counter++)
325 if (node->isFunction() || node->isName())
327 std::cout << node->getName();
329 else if (node->isOperator())
331 std::cout << node->getCharacter();
333 else if (node->isInteger())
335 std::cout << node->getInteger();
337 else if (node->isReal())
339 std::cout << node->getReal();
343 std::cout <<
"[" << node->getType() <<
"]";
346 std::cout << std::endl;
348 for (counter = 0; counter < node->getNumChildren(); counter++)
350 ConverterASTNode::printASTNode(node->getChild(counter), indent + 2);
353 #endif // COPASI_DEBUG
357 return static_cast<ASTNode*
>(this->mChildren->remove(index));
367 while (pTmp->getNumChildren() > 0)
372 ASTNode* pCopy = pTmp->deepCopy();
377 #endif // LIBSBML_USE_LEGACY_MATH
bool isNumber(const std::string &str)
virtual size_t size() const
void setChildren(List *children)
static ASTNode * shallowCopy(const ASTNode *pOrig)
ASTNode * removeChild(unsigned int index)