void ASTCSymbolDelayNode::write(XMLOutputStream& stream) const { if (&stream == NULL) return; stream.startElement("apply"); stream.startElement("csymbol"); stream.setAutoIndent(false); ASTBase::writeAttributes(stream); stream.writeAttribute( "encoding" , mEncoding ); stream.writeAttribute( "definitionURL", mDefinitionURL ); stream << " " << getName() << " "; stream.endElement("csymbol"); stream.setAutoIndent(true); for (unsigned int n = 0; n < getNumChildren(); n++) { ASTFunctionBase::getChild(n)->write(stream); } stream.endElement("apply"); }
void ASTPiecewiseFunctionNode::write(XMLOutputStream& stream) const { if (&stream == NULL) return; ASTBase::writeStartElement(stream); unsigned int i; unsigned int numChild = 0; unsigned int numChildren = ASTFunctionBase::getNumChildren(); for (i = 0; i < getNumPiece(); i++) { /* HACK TO REPLICATE OLD AST */ /* old ast behaviour would take each child in turn as elements of piece * and then otherwise */ if (ASTFunctionBase::getChild(i)->getType() == AST_CONSTRUCTOR_PIECE) { ASTFunctionBase::getChild(i)->write(stream); } else { stream.startElement("piece"); if (numChild < numChildren) { ASTFunctionBase::getChild(numChild)->write(stream); numChild++; } if (numChild < numChildren) { ASTFunctionBase::getChild(numChild)->write(stream); numChild++; } stream.endElement("piece"); } } if (getHasOtherwise() == true) { if (ASTFunctionBase::getChild(numChildren-1)->getType() == AST_CONSTRUCTOR_OTHERWISE) { ASTFunctionBase::getChild(numChildren-1)->write(stream); } else { stream.startElement("otherwise"); ASTFunctionBase::getChild(numChildren-1)->write(stream); stream.endElement("otherwise"); } } stream.endElement("piecewise"); }
/* * Subclasses should override this method to write out their contained * SBML objects as XML elements. Be sure to call your parents * implementation of this method as well. */ void SpeciesReference::writeElements (XMLOutputStream& stream) const { if ( mNotes != NULL ) stream << *mNotes; SpeciesReference * sr = const_cast <SpeciesReference *> (this); sr->syncAnnotation(); if ( mAnnotation != NULL ) stream << *mAnnotation; if (getLevel() == 2) { if (mStoichiometryMath || mDenominator != 1) { if (mStoichiometryMath != NULL) { mStoichiometryMath->write(stream); } else { ASTNode node; node.setValue(static_cast<long>(mStoichiometry), mDenominator); stream.startElement("stoichiometryMath"); writeMathML(&node, stream); stream.endElement("stoichiometryMath"); } } } // // (EXTENSION) // SBase::writeExtensionElements(stream); }
void ASTLambdaFunctionNode::write(XMLOutputStream& stream) const { ASTBase::writeStartElement(stream); /* HACK TO REPLICATE OLD AST */ /* all but the last child will be wrapped as bvars * even if they are technically not */ unsigned int numChildren = ASTFunctionBase::getNumChildren(); for (unsigned int i = 0; i < numChildren; i++) { if (i < numChildren-1 && ASTFunctionBase::getChild(i)->getType() != AST_QUALIFIER_BVAR) { ASTQualifierNode * bvar = new ASTQualifierNode(AST_QUALIFIER_BVAR); bvar->addChild(ASTFunctionBase::getChild(i)->deepCopy()); bvar->write(stream); delete bvar; } else { ASTFunctionBase::getChild(i)->write(stream); } } stream.endElement("lambda"); }
void ASTSemanticsNode::write(XMLOutputStream& stream) const { stream.startElement("semantics"); ASTBase::writeAttributes(stream); if (isSetDefinitionURL() == true) { stream.writeAttribute( "definitionURL", mDefinitionURL ); } if (getNumChildren() > 0) { getChild(0)->write(stream); } for (unsigned int n = 0; n < getNumSemanticsAnnotations(); n++) { stream << *getSemanticsAnnotation(n); } stream.endElement("semantics"); }
void ASTBase::writeConstant(XMLOutputStream& stream, const std::string & name) const { stream.startElement(name); writeAttributes(stream); stream.endElement(name); }
void ASTBase::writeNegInfinity(XMLOutputStream& stream) const { stream.startElement("apply"); stream.startEndElement("minus"); stream.startEndElement("infinity"); stream.endElement("apply"); }
void ASTBase::writeStartEndElement (XMLOutputStream& stream) const { const char * name = getNameFromType(getExtendedType()); stream.startElement(name); writeAttributes(stream); stream.endElement(name); }
/* * Writes (serializes) this SBML object by writing it to XMLOutputStream. */ void Text::write (XMLOutputStream& stream) const { stream.startElement( getElementName() ); writeAttributes( stream ); // in addition to attributes we need to write the characters stream << this->getText(); stream.endElement( getElementName() ); }
void PolygonObject::write(XMLOutputStream& stream) const { stream.startElement(getElementName(), getPrefix()); writeAttributes(stream); if(isSetPointIndex()) { for (int i = 0; i < mPointIndexLength; ++i) { stream << (long)mPointIndex[i] << " "; } } stream.endElement(getElementName(), getPrefix()); }
void ImageData::write(XMLOutputStream& stream) const { stream.startElement(getElementName(), getPrefix()); writeAttributes(stream); if(isSetSamples()) { for (int i = 0; i < mSamplesLength; ++i) { stream << (long)mSamples[i] << " "; } } stream.endElement(getElementName(), getPrefix()); }
/* * Writes this XMLNode and its children to stream. */ void XMLNode::write (XMLOutputStream& stream) const { if (&stream == NULL) return; unsigned int children = getNumChildren(); XMLToken::write(stream); if (children > 0) { bool haveTextNode = false; for (unsigned int c = 0; c < children; ++c) { const XMLNode& current = getChild(c); stream << current; haveTextNode |= current.isText(); } if (!mTriple.isEmpty()) { // edge case ... we have an element with a couple of elements, and // one is a text node (ugly!) in this case we can get a hanging // indent ... so we downindent ... if (children > 1 && haveTextNode) { stream.downIndent(); } stream.endElement( mTriple ); } } else if ( isStart() && !isEnd() ) { stream.endElement( mTriple ); } }
void ASTUnaryFunctionNode::write(XMLOutputStream& stream) const { if (&stream == NULL) return; stream.startElement("apply"); //const char * name = ASTBase::getNameFromType(type); ASTBase::writeStartEndElement(stream); /* write the one child * note we expect to have one child but cannot guarantee it */ unsigned int numChildren = getNumChildren(); /* HACK TO REPLICATE OLD AST */ /* for log 10 write out the logbase explicilty * for sqrt write out the degree explicilty * NOTE the qualifier node will add the necessary integers */ if (numChildren == 1) { if (isLog10() == true) { ASTQualifierNode * logbase = new ASTQualifierNode(AST_QUALIFIER_LOGBASE); logbase->write(stream); delete logbase; } else if (isSqrt() == true) { ASTQualifierNode * degree = new ASTQualifierNode(AST_QUALIFIER_DEGREE); degree->write(stream); delete degree; } ASTFunctionBase::getChild(0)->write(stream); } else { for (unsigned int n = 0; n < numChildren; n++) { ASTFunctionBase::getChild(n)->write(stream); } } stream.endElement("apply"); }
/* * Writes this XMLToken to stream. */ void XMLToken::write (XMLOutputStream& stream) const { if ( isEOF () ) return; if ( isText() ) { stream << getCharacters(); return; } if ( isStart() ) stream.startElement( mTriple ); if ( isStart() ) stream << mNamespaces << mAttributes; if ( isEnd() ) stream.endElement( mTriple ); }
void ASTCnExponentialNode::write(XMLOutputStream& stream) const { stream.startElement("cn"); stream.setAutoIndent(false); ASTCnBase::write(stream); writeENotation ( getMantissa(), getExponent(), stream); stream.endElement("cn"); stream.setAutoIndent(true); }
void ASTNaryFunctionNode::writeNodeOfType(XMLOutputStream& stream, int type, bool inChildNode) const { if (inChildNode == false) { stream.startElement("apply"); ASTBase::writeStartEndElement(stream); } unsigned int numChildren = getNumChildren(); { for (unsigned int i = 0; i < numChildren; i++) { if (ASTFunctionBase::getChild(i)->getType() == type) { ASTFunction* fun = dynamic_cast<ASTFunction*>(ASTFunctionBase::getChild(i)); if (fun != NULL) { fun->writeNodeOfType(stream, type, true); } else { ASTNode* newAST = dynamic_cast<ASTNode*>(ASTFunctionBase::getChild(i)); if (newAST != NULL) { newAST->writeNodeOfType(stream, type, true); } } } else { ASTFunctionBase::getChild(i)->write(stream); } } } if (inChildNode == false) { stream.endElement("apply"); } }
void ASTCnIntegerNode::write(XMLOutputStream& stream) const { stream.startElement("cn"); stream.setAutoIndent(false); ASTCnBase::write(stream); static const string type = "integer"; stream.writeAttribute("type", type); stream << " " << getInteger() << " "; stream.endElement("cn"); stream.setAutoIndent(true); }
void ASTArraysVectorFunctionNode::write(XMLOutputStream& stream) const { std::string name = getNameFromType(this->getExtendedType()); stream.startElement(name); ASTBase::writeAttributes(stream); /* write children */ for (unsigned int i = 0; i < ASTFunctionBase::getNumChildren(); i++) { ASTFunctionBase::getChild(i)->write(stream); } stream.endElement(name); }
void ASTCiNumberNode::write(XMLOutputStream& stream) const { stream.startElement("ci"); stream.setAutoIndent(false); ASTBase::writeAttributes(stream); if (isSetDefinitionURL() == true) { stream.writeAttribute("definitionURL", getDefinitionURL()); } stream << " " << getName() << " "; stream.endElement("ci"); stream.setAutoIndent(true); }
void ASTCnRealNode::write(XMLOutputStream& stream) const { stream.startElement("cn"); stream.setAutoIndent(false); ASTCnBase::write(stream); ostringstream output; output.precision(LIBSBML_DOUBLE_PRECISION); output << getReal(); string value_string = output.str(); string::size_type position = value_string.find('e'); if (position == string::npos) { stream << " " << value_string << " "; } else { const string mantissa_string = value_string.substr(0, position); const string exponent_string = value_string.substr(position + 1); double mantissa = strtod(mantissa_string.c_str(), 0); long exponent = strtol(exponent_string.c_str(), 0, 10); this->writeENotation(mantissa, exponent, stream); } stream.endElement("cn"); stream.setAutoIndent(true); }
void ASTNaryFunctionNode::write(XMLOutputStream& stream) const { int type = getType(); unsigned int numChildren = getNumChildren(); if (numChildren <= 2 && (type == AST_PLUS || type == AST_TIMES)) { writeNodeOfType(stream, type); } else if (type == AST_UNKNOWN && numChildren == 0) { // we have an empty apply tag stream.startEndElement("apply"); } else { stream.startElement("apply"); //const char * name = ASTBase::getNameFromType(type); ASTBase::writeStartEndElement(stream); /* write children */ /* HACK TO REPLICATE OLD AST */ /* for log/root with two or more children assume first is logbase/degree * and last is the value operated on * * however if the node is read in with a logbase and then more than * further children it uses the first as the value operated on */ if (type == AST_FUNCTION_ROOT) { if (numChildren > 1) { if (ASTFunctionBase::getChild(0)->getType() != AST_QUALIFIER_DEGREE) { ASTQualifierNode * logbase = new ASTQualifierNode(AST_QUALIFIER_DEGREE); logbase->addChild(ASTFunctionBase::getChild(0)->deepCopy()); logbase->write(stream); delete logbase; ASTFunctionBase::getChild(numChildren-1)->write(stream); } else { /* if there is only 1 child that is logbase we dont write either */ ASTFunctionBase::getChild(0)->write(stream); ASTFunctionBase::getChild(numChildren-1)->write(stream); } } else { ASTFunctionBase::getChild(0)->write(stream); } } else { for (unsigned int i = 0; i < ASTFunctionBase::getNumChildren(); i++) { ASTFunctionBase::getChild(i)->write(stream); } } stream.endElement("apply"); } }
void ASTBinaryFunctionNode::write(XMLOutputStream& stream) const { if (&stream == NULL) return; int type = getType(); stream.startElement("apply"); //const char * name = ASTBase::getNameFromType(type); ASTBase::writeStartEndElement(stream); /* HACK TO REPLICATE OLD AST */ /* for divide/power(operator) only write the first and last child * any other write all children */ /* write the two children * note we expect to have two children but cannot guarantee it */ unsigned int numChildren = getNumChildren(); if (type == AST_DIVIDE || type == AST_POWER) { if (numChildren > 0) { ASTFunctionBase::getChild(0)->write(stream); } if (numChildren > 1) { ASTFunctionBase::getChild(numChildren - 1)->write(stream); } } /* HACK TO REPLICATE OLD AST */ /* for log/root with two or more children assume first is logbase/degree * and last is the value operated on * * however if the node is read in with a logbase and then more than * further children it uses the first as the value operated on */ else if (type == AST_FUNCTION_LOG) { if (numChildren > 1) { if (ASTFunctionBase::getChild(0)->getType() != AST_QUALIFIER_LOGBASE) { ASTQualifierNode * logbase = new ASTQualifierNode(AST_QUALIFIER_LOGBASE); logbase->addChild(ASTFunctionBase::getChild(0)->deepCopy()); logbase->write(stream); delete logbase; ASTFunctionBase::getChild(numChildren-1)->write(stream); } else { /* if there is only 1 child that is logbase we dont write either */ ASTFunctionBase::getChild(0)->write(stream); ASTFunctionBase::getChild(numChildren-1)->write(stream); } } } else { for (unsigned int n = 0; n < numChildren; n++) { ASTFunctionBase::getChild(n)->write(stream); } } stream.endElement("apply"); }