bool ASTPiecewiseFunctionNode::read(XMLInputStream& stream, const std::string& reqd_prefix) { bool read = false; ASTBase * child = NULL; unsigned int numPiece = getNumPiece(); unsigned int numChildrenAdded = 0; // read in piece // these are functions as they will be created as ASTQualifierNodes while(numChildrenAdded < numPiece) { child = new ASTFunction(); read = child->read(stream, reqd_prefix); if (read == true && addChild(child, true) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; } else { read = false; break; } } // if there were no piece statements mark read true so we can continue if (numPiece == 0) { read = true; } if (read == true && getHasOtherwise() == true) { child = new ASTFunction(); read = child->read(stream, reqd_prefix); if (read == true && addChild(child, true) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; } else { read = false; } } return read; }
bool ASTUnaryFunctionNode::read(XMLInputStream& stream, const std::string& reqd_prefix) { bool read = false; ASTBase * child = NULL; const XMLToken element = stream.peek (); ASTBase::checkPrefix(stream, reqd_prefix, element); const char* name = element.getName().c_str(); setType(getTypeFromName(name)); ASTBase::read(stream, reqd_prefix); unsigned int numChildrenAdded = 0; if (getExpectedNumChildren() > 0) { while (stream.isGood() && numChildrenAdded < getExpectedNumChildren()) { stream.skipText(); name = stream.peek().getName().c_str(); if (representsNumber(ASTBase::getTypeFromName(name)) == true) { child = new ASTNumber(); } else { child = new ASTFunction(); } read = child->read(stream, reqd_prefix); stream.skipText(); if (read == true && addChild(child) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; } else { delete child; child = NULL; read = false; break; } } } else { stream.skipPastEnd(element); read = true; } return read; }
bool ASTSemanticsNode::read(XMLInputStream& stream, const std::string& reqd_prefix) { bool read = false; ASTBase * child = NULL; const XMLToken element = stream.peek (); ASTBase::checkPrefix(stream, reqd_prefix, element); const char* name;// = element.getName().c_str(); if (stream.isGood())// && stream.peek().isEndFor(element) == false) { stream.skipText(); name = stream.peek().getName().c_str(); if (representsNumber(ASTBase::getTypeFromName(name)) == true) { child = new ASTNumber(); } else { child = new ASTFunction(); } read = child->read(stream, reqd_prefix); stream.skipText(); if (read == false || addChild(child) != LIBSBML_OPERATION_SUCCESS) { delete child; child = NULL; read = false; } } unsigned int i = 0; while ( i < getNumAnnotations()) { if (stream.peek().getName() == "annotation" || stream.peek().getName() == "annotation-xml") { XMLNode semanticAnnotation = XMLNode(stream); addSemanticsAnnotation(semanticAnnotation.clone()); i++; } else { stream.next(); } } return true; }
bool ASTNaryFunctionNode::read(XMLInputStream& stream, const std::string& reqd_prefix) { bool read = false; ASTBase * child = NULL; const XMLToken element = stream.peek (); ASTBase::checkPrefix(stream, reqd_prefix, element); const char* name = element.getName().c_str(); int type = getTypeFromName(name); setType(type); ASTBase::read(stream, reqd_prefix); unsigned int numChildrenAdded = 0; if (getExpectedNumChildren() > 0) { while (stream.isGood() && numChildrenAdded < getExpectedNumChildren()) { stream.skipText(); name = stream.peek().getName().c_str(); if (representsNumber(ASTBase::getTypeFromName(name)) == true) { child = new ASTNumber(); } else { child = new ASTFunction(); } read = child->read(stream, reqd_prefix); stream.skipText(); if (read == true && addChild(child) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; } else { delete child; child = NULL; read = false; break; } } } else { stream.skipPastEnd(element); read = true; } if (read == true && type == AST_FUNCTION_ROOT && getExpectedNumChildren() == 1 && ASTFunctionBase::getChild(0)->getType() != AST_QUALIFIER_DEGREE) { /* HACK TO REPLICATE OLD BEHAVIOUR */ /* we need to add the qualifier child for the degree 2 */ ASTFunction * degree = new ASTFunction(AST_QUALIFIER_DEGREE); ASTNumber * int2 = new ASTNumber(AST_INTEGER); int2->setInteger(2); degree->addChild(int2->deepCopy()); this->prependChild(degree->deepCopy()); delete int2; delete degree; } //if (read == false) //{ // stream.skipPastEnd(element); //} return read; }
bool ASTCSymbolDelayNode::read(XMLInputStream& stream, const std::string& reqd_prefix) { bool read = false; XMLToken element = stream.peek (); const string& nameE = element.getName(); if (nameE != "csymbol") { #if 0 cout << "HELP\n"; #endif return read; } ASTBase::read(stream, reqd_prefix); const string nameDelay = trim( stream.next().getCharacters() ); setName((nameDelay)); ASTBase::setType(AST_FUNCTION_DELAY); stream.skipPastEnd(element); const char * name; ASTBase * child = NULL; unsigned int numChildrenAdded = 0; // catch if we do not have two children if (getExpectedNumChildren() > 0) { while (stream.isGood() && numChildrenAdded < getExpectedNumChildren()) { stream.skipText(); name = stream.peek().getName().c_str(); if (representsNumber(ASTBase::getTypeFromName(name)) == true) { child = new ASTNumber(); } else { child = new ASTFunction(); } read = child->read(stream, reqd_prefix); stream.skipText(); if (read == true && addChild(child) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; } else { read = false; break; } } } else { stream.skipPastEnd(element); read = true; } return read; }
bool ASTLambdaFunctionNode::read(XMLInputStream& stream, const std::string& reqd_prefix) { bool read = false; ASTBase * child = NULL; const char* name; unsigned int numBvars = getNumBvars(); unsigned int numChildrenAdded = 0; // read in bvars // these are functions as they will be created as ASTQualifierNodes while(numChildrenAdded < numBvars) { child = new ASTFunction(); read = child->read(stream, reqd_prefix); if (read == true && addChild(child, true) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; } else { delete child; child = NULL; read = false; break; } } // if we had no bvars to read mark read as true so we will continue if (numBvars == 0) { read = true; } while (read == true && stream.isGood() && numChildrenAdded < getExpectedNumChildren()) { stream.skipText(); name = stream.peek().getName().c_str(); if (representsNumber(ASTBase::getTypeFromName(name)) == true) { child = new ASTNumber(); } else { child = new ASTFunction(); } /* read = */ child->read(stream, reqd_prefix); stream.skipText(); if (addChild(child) == LIBSBML_OPERATION_SUCCESS) { numChildrenAdded++; read = true; } else { delete child; child = NULL; read = false; break; } } return read; }