LIBSBML_EXTERN void copySBaseAttributes(const SBase& source,SBase& target) { target.setMetaId(source.getMetaId()); // target.setId(source.getId()); // target.setName(source.getName()); target.setSBMLDocument(const_cast<SBMLDocument*>(source.getSBMLDocument())); target.setSBOTerm(source.getSBOTerm()); if(source.isSetAnnotation()) { target.setAnnotation(new XMLNode(*const_cast<SBase&>(source).getAnnotation())); } if(source.isSetNotes()) { target.setNotes(new XMLNode(*const_cast<SBase&>(source).getNotes())); } if (source.getSBMLNamespaces()) { target.setSBMLNamespaces(source.getSBMLNamespaces()); } List* pCVTerms=target.getCVTerms(); // first delete all the old CVTerms if(pCVTerms) { while(pCVTerms->getSize()>0) { CVTerm* object=static_cast<CVTerm*>(pCVTerms->remove(0)); delete object; } // add the cloned CVTerms from source if(source.getCVTerms()!=NULL) { unsigned int i=0,iMax=source.getCVTerms()->getSize(); while(i<iMax) { target.addCVTerm(static_cast<CVTerm*>(static_cast<CVTerm*>(source.getCVTerms()->get(i))->clone())); ++i; } } } }
/** @cond doxygenLibsbmlInternal */ void CompModelPlugin::resetPorts() { for (unsigned int p=0; p<getNumPorts(); p++) { Port* port = getPort(p); SBase* referenced = port->getReferencedElement(); if (port->isSetSBaseRef()) { port->unsetSBaseRef(); port->unsetIdRef(); port->unsetMetaIdRef(); port->unsetUnitRef(); int type = referenced->getTypeCode(); if (referenced->isSetId() && type != SBML_INITIAL_ASSIGNMENT && type != SBML_ASSIGNMENT_RULE && type != SBML_RATE_RULE && type != SBML_EVENT_ASSIGNMENT) { if (type==SBML_UNIT_DEFINITION) { port->setUnitRef(referenced->getId()); } else { port->setIdRef(referenced->getId()); } } else if (referenced->isSetMetaId()) { port->setMetaIdRef(referenced->getMetaId()); } else { stringstream newname; newname << "auto_port_" << p; referenced->setMetaId(newname.str()); port->setMetaIdRef(newname.str()); } } port->clearReferencedElement(); } }
int ReplacedBy::performReplacementAndCollect(set<SBase*>* removed, set<SBase*>* toremove) { SBMLDocument* doc = getSBMLDocument(); //Find the various objects and plugin objects we need for this to work. SBase* parent = getParentSBMLObject(); if (parent==NULL) { if (doc) { string error = "Unable to perform replacement in ReplacedBy::performReplacement: no parent object for this <replacedBy> could be found."; doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn()); } return LIBSBML_INVALID_OBJECT; } SBase* ref = getReferencedElement(); if (ref==NULL) { //getReferencedElement sets its own error messages. return LIBSBML_INVALID_OBJECT; } //Update the IDs. (Will set its own error messages.) int ret = updateIDs(ref, parent); //ReplacedBy elements do get the name of the top-level element, assuming it has one: if (parent->isSetId()) { ref->setId(parent->getId()); } if (parent->isSetMetaId()) { ref->setMetaId(parent->getMetaId()); } if (ret != LIBSBML_OPERATION_SUCCESS) return ret; //And finally, get ready to delete the parent object. if (toremove) { toremove->insert(parent); } return LIBSBML_OPERATION_SUCCESS; }