/* * Helper to log a common type of error. */ void SBasePlugin::logUnknownElement(const std::string &element, const unsigned int sbmlLevel, const unsigned int sbmlVersion, const unsigned int pkgVersion ) { if(&element == NULL) return; std::ostringstream msg; msg << "Element '" << element << "' is not part of the definition of " << "SBML Level " << sbmlLevel << " Version " << sbmlVersion << " Package \"" << mSBMLExt->getName() << "\" Version " << pkgVersion << "."; // // (TODO) Additional class such as SBMLExtensionError and SBMLExtensionErrorLog // may need to be implemented // SBMLErrorLog* errlog = getErrorLog(); if (errlog) { errlog->logError(UnrecognizedElement, sbmlLevel, sbmlVersion, msg.str()); } }
static SBMLDocument *checkedReadSBMLFromString(const char* xml) { SBMLDocument *doc = readSBMLFromString(xml); if (doc) { if (doc->getModel() == 0) { // fatal error SBMLErrorLog *log = doc->getErrorLog(); string errors = log ? log->toString() : " NULL SBML Error Log"; delete doc; throw_llvm_exception("Fatal SBML error, no model, errors in sbml document: " + errors); } else if (doc->getNumErrors() > 0) { SBMLErrorLog *log = doc->getErrorLog(); string errors = log ? log->toString() : " NULL SBML Error Log"; Log(rr::Logger::LOG_WARNING) << "Warning, errors found in sbml document: " + errors; } } else { delete doc; throw_llvm_exception("readSBMLFromString returned NULL, no further information available"); } return doc; }
/* * Helper to log a common type of error. */ void SBasePlugin::logUnknownAttribute(const std::string &attribute, const unsigned int sbmlLevel, const unsigned int sbmlVersion, const unsigned int pkgVersion, const std::string& element) { if (&attribute == NULL || &element == NULL) return; std::ostringstream msg; msg << "Attribute '" << attribute << "' is not part of the " << "definition of an SBML Level " << sbmlLevel << " Version " << sbmlVersion << " Package \"" << mSBMLExt->getName() << "\" Version " << pkgVersion << " on " << element << " element."; // // (TODO) Additional class such as SBMLExtensionError and SBMLExtensionErrorLog // may need to be implemented // SBMLErrorLog* errlog = getErrorLog(); if (errlog) { errlog->logError(NotSchemaConformant, sbmlLevel, sbmlVersion, msg.str()); } }
/* * Helper to log a common type of error. */ void SBasePlugin::logEmptyString(const std::string &attribute, const unsigned int sbmlLevel, const unsigned int sbmlVersion, const unsigned int pkgVersion, const std::string& element) { if (&attribute == NULL || &element == NULL) return; std::ostringstream msg; msg << "Attribute '" << attribute << "' on an " << element << " of package \"" << mSBMLExt->getName() << "\" version " << pkgVersion << " must not be an empty string."; // // (TODO) Additional class such as SBMLExtensionError and SBMLExtensionErrorLog // may need to be implemented // SBMLErrorLog* errlog = getErrorLog(); if (errlog) { errlog->logError(NotSchemaConformant, sbmlLevel, sbmlVersion, msg.str()); } }
bool hasActualErrors(SBMLDocument* document) { document->checkConsistency(); for (unsigned int e=0; e<document->getNumErrors(); e++) { if (document->getError(e)->getSeverity() >= LIBSBML_SEV_ERROR) return true; } #ifdef USE_COMP CompModelPlugin* compmod = static_cast<CompModelPlugin*>(document->getModel()->getPlugin("comp")); if (compmod != NULL && compmod->getNumSubmodels() > 0) { SBMLDocument flat(*document); ConversionProperties* props = new ConversionProperties(); props->addOption("flatten comp"); SBMLConverter* converter = SBMLConverterRegistry::getInstance().getConverterFor(*props); converter->setDocument(&flat); int result = converter->convert(); flat.checkConsistency(); bool flaterrors = false; SBMLErrorLog* errlog = document->getErrorLog(); for (unsigned int e=0; e<flat.getNumErrors(); e++) { if (flat.getError(e)->getSeverity() >= LIBSBML_SEV_ERROR) { flaterrors = true; errlog->add(*(flat.getError(e))); } } if (flaterrors) return true; } #endif return false; }
unsigned int RenderSBMLDocumentPlugin::checkConsistency() { unsigned int nerrors = 0; unsigned int total_errors = 0; SBMLDocument* doc = static_cast<SBMLDocument *>(this->getParentSBMLObject()); SBMLErrorLog *log = doc->getErrorLog(); unsigned char applicableValidators = doc->getApplicableValidators(); /* determine which validators to run */ bool id = ((applicableValidators & 0x01) == 0x01); bool sbml = ((applicableValidators & 0x02) == 0x02); /* LIST OTHERS HERE */ RenderIdentifierConsistencyValidator id_validator; RenderConsistencyValidator validator; /* LIST OTHERS HERE */ if (id) { id_validator.init(); nerrors = id_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add(id_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { return total_errors; } } } if (sbml) { validator.init(); nerrors = validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add(validator.getFailures() ); // DO NOT NEED THIS IN LAST CALL // /* only want to bail if errors not warnings */ // if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) // { // return total_errors; // } } } /* ADD OTHERS HERE */ return total_errors; }
END_TEST START_TEST (test_comp_flatten_unknown_withValidation_nostrip_5) { SBMLDocument* doc = TestFlattenedUnknownValidateNoStrip("unknown5.xml", "unknown5_flat_stay.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 0); //fail_unless(errors->contains(UnrequiredPackagePresent) == true); //fail_unless(errors->contains(CompFlatteningNotRecognisedNotReqd) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_17) { SBMLDocument* doc = TestFlattenedUnknownNoValidate("unknown17.xml", "unknown17_flat.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 3); fail_unless(errors->contains(UnrequiredPackagePresent) == true); fail_unless(errors->contains(CompFlatteningNotRecognisedNotReqd) == true); fail_unless(errors->contains(CompIdRefMayReferenceUnknownPackage) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_20) { SBMLDocument* doc = TestFlattenedUnknownAbortNone("unknown20.xml", "unknown20_flat.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 4); fail_unless(errors->contains(RequiredPackagePresent) == true); fail_unless(errors->contains(CompFlatteningNotRecognisedReqd) == true); fail_unless(errors->contains(CompIdRefMayReferenceUnknownPackage) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_withValidation_nostrip_4) { SBMLDocument* doc = TestFlattenedUnknownValidateNoStrip("unknown4.xml", "unknown4_flat_stay.xml"); SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 0); //fail_unless(errors->contains(RequiredPackagePresent) == true); //fail_unless(errors->contains(CompFlatteningNotRecognisedReqd) == true); //fail_unless(errors->contains(CompLineNumbersUnreliable) == true); //fail_unless(errors->contains(CompIdRefMayReferenceUnknownPackage) == true); delete doc; }
END_TEST START_TEST (test_comp_flatten_unknown_21) { string filename(TestDataDirectory); //string filename("C:\\Development\\libsbml\\src\\sbml\\packages\\comp\\util\\test\\test-data\\"); ConversionProperties props; props.addOption("flatten comp"); props.addOption("basePath", filename); props.addOption("performValidation", false); SBMLConverter* converter = SBMLConverterRegistry::getInstance().getConverterFor(props); // load document string cfile = filename + "flatten_fail_unknown.xml"; SBMLDocument* doc = readSBMLFromFile(cfile.c_str()); // fail if there is no model (readSBMLFromFile always returns a valid document) fail_unless(doc->getModel() != NULL); // write the doc before we attempt conversion string newModel = writeSBMLToStdString(doc); converter->setDocument(doc); int result = converter->convert(); // we should fail because we are testing the restoreNamespaces function fail_unless(result == LIBSBML_OPERATION_FAILED); string flatModel = writeSBMLToStdString(doc); fail_unless(flatModel == newModel); delete converter; SBMLErrorLog* errors = doc->getErrorLog(); fail_unless(errors->getNumErrors() == 2); fail_unless(errors->contains(RequiredPackagePresent) == true); fail_unless(errors->contains(CompFlatteningNotRecognisedReqd) == true); //fail_unless(errors->contains(CompModelFlatteningFailed) == true); //fail_unless(errors->contains(CompSubmodelMustReferenceModel) == true); delete doc; }
std::string validateSBML(const std::string src, unsigned opt) { std::stringstream errors; SBMLDocument *doc = NULL; try { string sbml = SBMLReader::read(src); doc = readSBMLFromString (sbml.c_str()); doc->setConsistencyChecks(LIBSBML_CAT_GENERAL_CONSISTENCY, opt & VALIDATE_GENERAL); doc->setConsistencyChecks(LIBSBML_CAT_UNITS_CONSISTENCY, opt & VALIDATE_UNITS); doc->setConsistencyChecks(LIBSBML_CAT_IDENTIFIER_CONSISTENCY, opt & VALIDATE_IDENTIFIER); doc->setConsistencyChecks(LIBSBML_CAT_MATHML_CONSISTENCY, opt & VALIDATE_MATHML); doc->setConsistencyChecks(LIBSBML_CAT_OVERDETERMINED_MODEL, opt & VALIDATE_OVERDETERMINED); doc->setConsistencyChecks(LIBSBML_CAT_MODELING_PRACTICE, opt & VALIDATE_MODELING_PRACTICE); doc->checkConsistency(); SBMLErrorLog* errorLog = doc->getErrorLog(); if(errorLog) { errorLog->printErrors(errors); } } catch(...) { delete doc; throw; } delete doc; return errors.str(); }
/* * Reads the expected attributes into the member data variables */ void ClassOne::readV2Attributes(const XMLAttributes& attributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); bool assigned = false; unsigned int pkgVersion = getPackageVersion(); SBMLErrorLog* log = getErrorLog(); unsigned int numErrs; // // id SId (use = "required" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<ClassOne>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(VersIdSyntaxRule, level, version, "The id '" + mId + "' does not " "conform to the syntax."); } } else { std::string message = "Vers attribute 'id' is missing from the <ClassOne> " "element."; log->logPackageError("vers", VersClassOneAllowedAttributes, pkgVersion, level, version, message); } // // att2 bool (use = "optional" ) // mIsSetAtt2 = attributes.readInto("att2", mAtt2); }
/** @cond doxygenLibsbmlInternal */ SBase* SBaseRef::createObject (XMLInputStream& stream) { SBase* object = NULL; const std::string& name = stream.peek().getName(); const XMLNamespaces& xmlns = stream.peek().getNamespaces(); const std::string& prefix = stream.peek().getPrefix(); const std::string& targetPrefix = (xmlns.hasURI(mURI)) ? xmlns.getPrefix(mURI) : getPrefix(); if (prefix == targetPrefix) { SBMLErrorLog* errlog = getErrorLog(); if (mSBaseRef != NULL && (name =="sBaseRef" || name=="sbaseRef")) { if (errlog != NULL) { errlog->logPackageError(getPackageName(), CompOneSBaseRefOnly, getPackageVersion(), getLevel(), getVersion()); } object = mSBaseRef; } else if ( name == "sBaseRef" ) { COMP_CREATE_NS(compns, getSBMLNamespaces()); mSBaseRef = new SBaseRef(compns); object = mSBaseRef; object->connectToParent(this); delete compns; } else if ( name == "sbaseRef" ) { if (errlog != NULL) { errlog->logPackageError(getPackageName(), CompDeprecatedSBaseRefSpelling, getPackageVersion(), getLevel(), getVersion()); } COMP_CREATE_NS(compns, getSBMLNamespaces()); mSBaseRef = new SBaseRef(compns); object = mSBaseRef; object->connectToParent(this); delete compns; } } return object; }
/* * Reads the expected attributes into the member data variables */ void ClassOne::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("vers", VersClassOneAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("vers", VersClassOneAllowedCoreAttributes, pkgVersion, level, version, details); } } if (pkgVersion == 1) { readV1Attributes(attributes); } else { readV2Attributes(attributes); } }
void checkBooleans(SBMLDocument* doc, set<string>& components, set<string>& tests) { if (doc->getLevel() < 3) { return; } if (doc->getVersion() < 2) { return; } SBMLDocument* translatedDoc = doc->clone(); if (translatedDoc->setLevelAndVersion(3, 1, true)) { //Successful translation means that there is no use of booleans in numeric contexts, or visa versa. return; } SBMLErrorLog* errlog = translatedDoc->getErrorLog(); if (errlog->contains(10209) || errlog->contains(10210) || errlog->contains(10211) || errlog->contains(10212) || errlog->contains(10213) || errlog->contains(10217) || errlog->contains(98006) || errlog->contains(21202) || errlog->contains(21001)) { tests.insert("BoolNumericSwap"); } }
void CompSBasePlugin::logInvalidId(const std::string& attribute, const std::string& wrongattribute) { bool knownelement = (getParentSBMLObject() == NULL); std::ostringstream msg; msg << "Setting the attribute '" << attribute << "' "; if (knownelement) { msg << "of a <" << getParentSBMLObject()->getElementName() << "> "; } msg << "in the " << getPackageName() << " package (version " << getPackageVersion() << ") to '" << wrongattribute << "' is illegal: the string is not a well-formed SId."; SBMLErrorLog* errlog = getErrorLog(); if (errlog) { errlog->logError(NotSchemaConformant, getLevel(), getVersion(), msg.str()); } }
/* * Writes the given SBML document to the output stream. * * @return true on success and false if one of the underlying parser * components fail (rare). */ bool SBMLWriter::writeSBML (const SBMLDocument* d, std::ostream& stream) { bool result = false; try { stream.exceptions(ios_base::badbit | ios_base::failbit | ios_base::eofbit); XMLOutputStream xos(stream, "UTF-8", true, mProgramName, mProgramVersion); d->write(xos); stream << endl; result = true; } catch (ios_base::failure&) { SBMLErrorLog *log = (const_cast<SBMLDocument *>(d))->getErrorLog(); log->logError(XMLFileOperationError); } return result; }
int Registry::CheckAndAddSBMLIfGood(SBMLDocument* document) { document->setConsistencyChecks(LIBSBML_CAT_UNITS_CONSISTENCY, false); document->checkConsistency(); SBMLErrorLog* log = document->getErrorLog(); if (log->getNumFailsWithSeverity(2) == 0 && log->getNumFailsWithSeverity(3) == 0) { //It's a valid SBML file. const Model* sbml = document->getModel(); string sbmlname = getNameFromSBMLObject(sbml, "file"); if (sbmlname != MAINMODULE) { while (NewCurrentModule(&sbmlname)) { //Duplicated module name sbmlname += "_"; } } CurrentModule()->LoadSBML(document); if (sbmlname != MAINMODULE) { RevertToPreviousModule(); } return 2; } return 0; }
END_TEST START_TEST(test_SBMLErrorLog_removeAll) { SBMLErrorLog log; // add errors log.add(SBMLError(1234, 2, 4)); log.add(SBMLError(1234, 2, 4)); log.add(SBMLError(1234, 2, 4)); log.add(SBMLError(1234, 2, 4)); fail_unless(log.contains(1234) == true); log.remove(1234); fail_unless(log.contains(1234) == true); log.removeAll(1234); fail_unless(log.contains(1234) == false); }
int CompModelPlugin::saveAllReferencedElements(set<SBase*> uniqueRefs, set<SBase*> replacedBys) { SBMLDocument* doc = getSBMLDocument(); Model* model = static_cast<Model*>(getParentSBMLObject()); if (model==NULL) { if (doc) { string error = "Unable to discover any referenced elements in CompModelPlugin::saveAllReferencedElements: no Model parent of the 'comp' model plugin."; doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error); } return LIBSBML_OPERATION_FAILED; } int ret = LIBSBML_OPERATION_SUCCESS; //Get a list of everything, pull out anything that's a deletion, replacement, or port, and save what they're pointing to. //At the same time, make sure that no two things point to the same thing. set<SBase*> RE_deletions = set<SBase*>(); //Deletions only point to things in the same model. List* allElements = model->getAllElements(); string modname = "the main model in the document"; if (model->isSetId()) { modname = "the model '" + model->getId() + "'"; } set<SBase*> todelete; for (unsigned int el=0; el<allElements->getSize(); el++) { SBase* element = static_cast<SBase*>(allElements->get(el)); int type = element->getTypeCode(); if (type==SBML_COMP_DELETION || type==SBML_COMP_REPLACEDBY || type==SBML_COMP_REPLACEDELEMENT || type==SBML_COMP_PORT) { //Don't worry about SBML_COMP_SBASEREF because they're all children of one of the above types. SBaseRef* reference = static_cast<SBaseRef*>(element); ReplacedElement* re = static_cast<ReplacedElement*>(element); ret = reference->saveReferencedElement(); if (ret != LIBSBML_OPERATION_SUCCESS) { if (type != SBML_COMP_REPLACEDBY && doc) { SBMLErrorLog* errlog = doc->getErrorLog(); SBMLError* lasterr = const_cast<SBMLError*> (doc->getErrorLog()->getError(doc->getNumErrors()-1)); if ( (errlog->contains(UnrequiredPackagePresent) || errlog->contains(RequiredPackagePresent))) { if ( lasterr->getErrorId() == CompIdRefMustReferenceObject) { //Change the error into a warning string fullmsg = lasterr->getMessage() + " However, this may be because of the unrecognized " + "package present in this document: ignoring this " + "element and flattening anyway."; errlog->remove(lasterr->getErrorId()); errlog->logPackageError("comp", CompIdRefMayReferenceUnknownPackage, getPackageVersion(), getLevel(), getVersion(), fullmsg, element->getLine(), element->getColumn(), LIBSBML_SEV_WARNING); } else if ( lasterr->getErrorId() == CompMetaIdRefMustReferenceObject) { //Change the error into a warning string fullmsg = lasterr->getMessage() + " However, this may be because of the unrecognized " + "package present in this document: ignoring this " + "element and flattening anyway."; errlog->remove(lasterr->getErrorId()); errlog->logPackageError("comp", CompMetaIdRefMayReferenceUnknownPkg, getPackageVersion(), getLevel(), getVersion(), fullmsg, element->getLine(), element->getColumn(), LIBSBML_SEV_WARNING); } } //Whether or not we could figure out the error, we can always still continue flattening. todelete.insert(element); continue; } else { delete allElements; return ret; } } SBase* direct = reference->getDirectReference(); bool adddirect = true; if (type == SBML_COMP_REPLACEDBY) { SBase* rbParent = reference->getParentSBMLObject(); if (uniqueRefs.insert(rbParent).second == false) { if (doc) { string error = "Error discovered in CompModelPlugin::saveAllReferencedElements when checking " + modname + ": a <" + rbParent->getElementName() + "> "; if (direct->isSetId()) { error += "with the id '" + rbParent->getId() + "'"; if (rbParent->isSetMetaId()) { error += ", and the metaid '" + rbParent->getMetaId() + "'"; } } else if (rbParent->isSetMetaId()) { error += "with the metaId '" + rbParent->getMetaId() + "'"; } error += " has a <replacedBy> child and is also pointed to by a <port>, <deletion>, <replacedElement>, or one or more <replacedBy> objects."; doc->getErrorLog()->logPackageError("comp", CompNoMultipleReferences, getPackageVersion(), getLevel(), getVersion(), error); } delete allElements; return LIBSBML_OPERATION_FAILED; } adddirect = replacedBys.insert(direct).second; } if (type==SBML_COMP_REPLACEDELEMENT && re->isSetDeletion()) { adddirect = RE_deletions.insert(direct).second; } if (adddirect) { if (uniqueRefs.insert(direct).second == false) { if (doc) { string error = "Error discovered in CompModelPlugin::saveAllReferencedElements when checking " + modname + ": "; if (replacedBys.find(direct) != replacedBys.end()) { error += "one or more <replacedBy> elements, plus a <deletion>, <replacedElement>, or <port> element"; } else if (RE_deletions.find(direct) != RE_deletions.end()) { error += "one or more <replacedElement> elements using a 'deletion' attribute, plus a <deletion>, <replacedElement>, or <port> element"; } else { error += "multiple <deletion>, <replacedElement>, and/or <port> elements"; } error += " point directly to the <" + direct->getElementName() + "> "; if (direct->isSetId()) { error += "with the id '" + direct->getId() + "'"; if (direct->isSetMetaId()) { error += ", and the metaid '" + direct->getMetaId() + "'"; } error += "."; } else if (direct->isSetMetaId()) { error += "with the metaId '" + direct->getMetaId() + "'."; } doc->getErrorLog()->logPackageError("comp", CompNoMultipleReferences, getPackageVersion(), getLevel(), getVersion(), error); } delete allElements; return LIBSBML_OPERATION_FAILED; } } } } for(set<SBase*>::iterator el=todelete.begin(); el != todelete.end(); el++) { (*el)->removeFromParentAndDelete(); } delete allElements; //Now call saveAllReferencedElements for all instantiated submodels. for (unsigned long sm=0; sm<getNumSubmodels(); ++sm) { Model* sub = getSubmodel((unsigned int)sm)->getInstantiation(); if (sub==NULL) { return LIBSBML_OPERATION_FAILED; } CompModelPlugin* subplug = static_cast<CompModelPlugin*>(sub->getPlugin(getPrefix())); if (subplug==NULL) { return LIBSBML_OPERATION_FAILED; } ret = subplug->saveAllReferencedElements(uniqueRefs, replacedBys); if (ret != LIBSBML_OPERATION_SUCCESS) { return ret; } } return LIBSBML_OPERATION_SUCCESS; }
/* * Writes the given SBML document to filename. * * If the filename ends with @em .gz, the file will be compressed by @em gzip. * Similary, if the filename ends with @em .zip or @em .bz2, the file will be * compressed by @em zip or @em bzip2, respectively. Otherwise, the fill will be * uncompressed. * If the filename ends with @em .zip, a filename that will be added to the * zip archive file will end with @em .xml or @em .sbml. For example, the filename * in the zip archive will be @em test.xml if the given filename is @em test.xml.zip * or @em test.zip. Also, the filename in the archive will be @em test.sbml if the * given filename is @em test.sbml.zip. * * @note To create a gzip/zip file, underlying libSBML needs to be linked with zlib at * compile time. Also, underlying libSBML needs to be linked with bzip2 to create a * bzip2 file. * File unwritable error will be logged and @c false will be returned if a compressed * file name is given and underlying libSBML is not linked with the corresponding * required library. * SBMLWriter::hasZlib() and SBMLWriter::hasBzip2() can be used to check whether * underlying libSBML is linked with the library. * * @return true on success and false if the filename could not be opened * for writing. */ bool SBMLWriter::writeSBML (const SBMLDocument* d, const std::string& filename) { std::ostream* stream = NULL; try { // open an uncompressed XML file. if ( string::npos != filename.find(".xml", filename.length() - 4) ) { stream = new(std::nothrow) std::ofstream(filename.c_str()); } // open a gzip file else if ( string::npos != filename.find(".gz", filename.length() - 3) ) { stream = OutputCompressor::openGzipOStream(filename); } // open a bz2 file else if ( string::npos != filename.find(".bz2", filename.length() - 4) ) { stream = OutputCompressor::openBzip2OStream(filename); } // open a zip file else if ( string::npos != filename.find(".zip", filename.length() - 4) ) { std::string filenameinzip = filename.substr(0, filename.length() - 4); if ( ( string::npos == filenameinzip.find(".xml", filenameinzip.length() - 4) ) && ( string::npos == filenameinzip.find(".sbml", filenameinzip.length() - 5) ) ) { filenameinzip += ".xml"; } #if defined(WIN32) && !defined(CYGWIN) char sepr = '\\'; #else char sepr = '/'; #endif size_t spos = filenameinzip.rfind(sepr, filenameinzip.length() - 1); if( spos != string::npos ) { filenameinzip = filenameinzip.substr(spos + 1, filenameinzip.length() - 1); } stream = OutputCompressor::openZipOStream(filename, filenameinzip); } else { stream = new(std::nothrow) std::ofstream(filename.c_str()); } } catch ( ZlibNotLinked& ) { // libSBML is not linked with zlib. XMLErrorLog *log = (const_cast<SBMLDocument *>(d))->getErrorLog(); std::ostringstream oss; oss << "Tried to write " << filename << ". Writing a gzip/zip file is not enabled because " << "underlying libSBML is not linked with zlib."; log->add(XMLError( XMLFileUnwritable, oss.str(), 0, 0) ); return false; } catch ( Bzip2NotLinked& ) { // libSBML is not linked with bzip2. XMLErrorLog *log = (const_cast<SBMLDocument *>(d))->getErrorLog(); std::ostringstream oss; oss << "Tried to write " << filename << ". Writing a bzip2 file is not enabled because " << "underlying libSBML is not linked with bzip2."; log->add(XMLError( XMLFileUnwritable, oss.str(), 0, 0) ); return false; } if ( stream == NULL || stream->fail() || stream->bad()) { SBMLErrorLog *log = (const_cast<SBMLDocument *>(d))->getErrorLog(); log->logError(XMLFileUnwritable); delete stream; return false; } bool result = writeSBML(d, *stream); delete stream; return result; }
/* * Reads the expected attributes into the member data variables */ void CoordinateComponent::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfCoordinateComponents*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialGeometryLOCoordinateComponentsAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialGeometryLOCoordinateComponentsAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialCoordinateComponentAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialCoordinateComponentAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "required" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<CoordinateComponent>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(SpatialIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } else { std::string message = "Spatial attribute 'id' is missing from the " "<CoordinateComponent> element."; log->logPackageError("spatial", SpatialCoordinateComponentAllowedAttributes, pkgVersion, level, version, message); } // // type enum (use = "required" ) // std::string type; assigned = attributes.readInto("type", type); if (assigned == true) { if (type.empty() == true) { logEmptyString(type, level, version, "<CoordinateComponent>"); } else { mType = CoordinateKind_fromString(type.c_str()); if (CoordinateKind_isValid(mType) == 0) { std::string msg = "The type on the <CoordinateComponent> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + type + "', which is not a valid option."; log->logPackageError("spatial", SpatialCoordinateComponentTypeMustBeCoordinateKindEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Spatial attribute 'type' is missing."; log->logPackageError("spatial", SpatialCoordinateComponentAllowedAttributes, pkgVersion, level, version, message); } // // unit UnitSIdRef (use = "optional" ) // assigned = attributes.readInto("unit", mUnit); if (assigned == true) { if (mUnit.empty() == true) { logEmptyString(mUnit, level, version, "<CoordinateComponent>"); } else if (SyntaxChecker::isValidSBMLSId(mUnit) == false) { logError(SpatialCoordinateComponentUnitMustBeUnitSId, level, version, "The attribute unit='" + mUnit + "' does not conform to the syntax."); } } }
LIBSBML_CPP_NAMESPACE_BEGIN #ifdef __cplusplus static void parseChemicalFormula(std::string& chemicalFormula, SBMLErrorLog& errLog, unsigned int packageVersion, unsigned int level, unsigned int version) { std::vector< std::pair< std::string, int > > chemicalSymbols; int chemicalNumber; size_t index = 0; size_t sizeStr = chemicalFormula.size(); char c = chemicalFormula[index]; while (index < sizeStr) { stringstream elementName; stringstream elementCount; if (isupper(c) == 0) { std::string message = "Encountered '"; message += c; message += "' when expecting a capital letter."; errLog.logPackageError("fbc", FbcSpeciesFormulaMustBeString, packageVersion, level, version, message); // at this point we already *know* the formula is bad, at this point // the map generated woudl be invalid in any case, so we quit here. return; } else { elementName << c; index++; } // next char if (index < sizeStr) { c = chemicalFormula[index]; // is it a letter while (islower(c) != 0 && index < sizeStr) { elementName << c; index++; if (index < sizeStr) { c = chemicalFormula[index]; } else { break; } } // is the next char a number while (isdigit(c) != 0 && index < sizeStr) { elementCount << c; index++; if (index < sizeStr) { c = chemicalFormula[index]; } else { break; } } } const string& chemicalName = elementName.str(); const string& chemicalNum = elementCount.str(); // create the pair if (chemicalNum.empty() == true) { chemicalNumber = 1; } else { chemicalNumber = atoi(chemicalNum.c_str()); } chemicalSymbols.push_back(make_pair(chemicalName, chemicalNumber)); } }
/* * Reads the expected attributes into the member data variables */ void CSGNode::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfCSGNodes*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialCSGObjectLOCSGNodesAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialCSGObjectLOCSGNodesAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialCSGNodeAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialCSGNodeAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<CSGNode>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(SpatialIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } }
/* * Reads the expected attributes into the member data variables */ void ListOfGlobalRenderInformation::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; SBMLErrorLog* log = getErrorLog(); ListOf::readAttributes(attributes, expectedAttributes); if (log) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("render", RenderListOfLayoutsLOGlobalRenderInformationAllowedAttributes, pkgVersion, level, version, details, getLine(), getColumn()); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("render", RenderListOfLayoutsLOGlobalRenderInformationAllowedCoreAttributes, pkgVersion, level, version, details, getLine(), getColumn()); } } } // // majorVersion uint (use = "optional" ) // if (log) { numErrs = log->getNumErrors(); } mIsSetMajorVersion = attributes.readInto("versionMajor", mMajorVersion); if ( mIsSetMajorVersion == false && log) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Render attribute 'versionMajor' from the " "<ListOfGlobalRenderInformation> element must be an integer."; log->logPackageError("render", RenderListOfLayoutsVersionMajorMustBeNonNegativeInteger, pkgVersion, level, version, message, getLine(), getColumn()); } } // // minorVersion uint (use = "optional" ) // if (log) { numErrs = log->getNumErrors(); } mIsSetMinorVersion = attributes.readInto("versionMinor", mMinorVersion); if ( mIsSetMinorVersion == false && log) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Render attribute 'versionMinor' from the " "<ListOfGlobalRenderInformation> element must be an integer."; log->logPackageError("render", RenderListOfLayoutsVersionMinorMustBeNonNegativeInteger, pkgVersion, level, version, message, getLine(), getColumn()); } } }
/* * Reads the expected attributes into the member data variables */ void AnalyticVolume::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfAnalyticVolumes*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialAnalyticGeometryLOAnalyticVolumesAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialAnalyticGeometryLOAnalyticVolumesAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("spatial", SpatialAnalyticVolumeAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "required" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<AnalyticVolume>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(SpatialIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } else { std::string message = "Spatial attribute 'id' is missing from the " "<AnalyticVolume> element."; log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, message); } // // functionType enum (use = "required" ) // std::string functiontype; assigned = attributes.readInto("functionType", functiontype); if (assigned == true) { if (functiontype.empty() == true) { logEmptyString(functiontype, level, version, "<AnalyticVolume>"); } else { mFunctionType = FunctionKind_fromString(functiontype.c_str()); if (FunctionKind_isValid(mFunctionType) == 0) { std::string msg = "The functionType on the <AnalyticVolume> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + functiontype + "', which is not a valid option."; log->logPackageError("spatial", SpatialAnalyticVolumeFunctionTypeMustBeFunctionKindEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Spatial attribute 'functionType' is missing."; log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, message); } // // ordinal int (use = "optional" ) // numErrs = log->getNumErrors(); mIsSetOrdinal = attributes.readInto("ordinal", mOrdinal); if ( mIsSetOrdinal == false) { if (log->getNumErrors() == numErrs + 1 && log->contains(XMLAttributeTypeMismatch)) { log->remove(XMLAttributeTypeMismatch); std::string message = "Spatial attribute 'ordinal' from the " "<AnalyticVolume> element must be an integer."; log->logPackageError("spatial", SpatialAnalyticVolumeOrdinalMustBeInteger, pkgVersion, level, version, message); } } // // domainType SIdRef (use = "required" ) // assigned = attributes.readInto("domainType", mDomainType); if (assigned == true) { if (mDomainType.empty() == true) { logEmptyString(mDomainType, level, version, "<AnalyticVolume>"); } else if (SyntaxChecker::isValidSBMLSId(mDomainType) == false) { logError(SpatialAnalyticVolumeDomainTypeMustBeDomainType, level, version, "The attribute domainType='" + mDomainType + "' does not conform to the " "syntax."); } } else { std::string message = "Spatial attribute 'domainType' is missing from the " "<AnalyticVolume> element."; log->logPackageError("spatial", SpatialAnalyticVolumeAllowedAttributes, pkgVersion, level, version, message); } }
/* * Reads the expected attributes into the member data variables */ void Group::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); if (static_cast<ListOfGroups*>(getParentSBMLObject())->size() < 2) { numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("groups", GroupsGroupAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("groups", GroupsModelLOGroupsAllowedCoreAttributes, pkgVersion, level, version, details); } } } SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("groups", GroupsGroupAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("groups", GroupsGroupAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<Group>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { log->logPackageError("groups", GroupsIdSyntaxRule, pkgVersion, level, version, "The id on the <" + getElementName() + "> is '" + mId + "', which does not conform to the syntax.", getLine(), getColumn()); } } // // name string (use = "optional" ) // assigned = attributes.readInto("name", mName); if (assigned == true) { if (mName.empty() == true) { logEmptyString(mName, level, version, "<Group>"); } } // // kind enum (use = "required" ) // std::string kind; assigned = attributes.readInto("kind", kind); if (assigned == true) { if (kind.empty() == true) { logEmptyString(kind, level, version, "<Group>"); } else { mKind = GroupKind_fromString(kind.c_str()); if (GroupKind_isValid(mKind) == 0) { std::string msg = "The kind on the <Group> "; if (isSetId()) { msg += "with id '" + getId() + "'"; } msg += "is '" + kind + "', which is not a valid option."; log->logPackageError("groups", GroupsGroupKindMustBeGroupKindEnum, pkgVersion, level, version, msg); } } } else { std::string message = "Groups attribute 'kind' is missing."; log->logPackageError("groups", GroupsGroupAllowedAttributes, pkgVersion, level, version, message); } }
/* * Performs a set of semantic consistency checks on the document. Query * the results by calling getNumErrors() and getError(). * * @return the number of failed checks (errors) encountered. */ unsigned int SBMLInternalValidator::checkConsistency (bool writeDocument) { unsigned int nerrors = 0; unsigned int total_errors = 0; //if (getLevel() == 3) //{ // logError(L3NotSupported); // return 1; //} /* determine which validators to run */ bool id = ((mApplicableValidators & 0x01) == 0x01); bool sbml = ((mApplicableValidators & 0x02) == 0x02); bool sbo = ((mApplicableValidators & 0x04) == 0x04); bool math = ((mApplicableValidators & 0x08) == 0x08); bool units = ((mApplicableValidators & 0x10) == 0x10); bool over = ((mApplicableValidators & 0x20) == 0x20); bool practice = ((mApplicableValidators & 0x40) == 0x40); /* taken the state machine concept out for now if (LibSBMLStateMachine::isActive()) { units = LibSBMLStateMachine::getUnitState(); } */ IdentifierConsistencyValidator id_validator; ConsistencyValidator validator; SBOConsistencyValidator sbo_validator; MathMLConsistencyValidator math_validator; UnitConsistencyValidator unit_validator; OverdeterminedValidator over_validator; ModelingPracticeValidator practice_validator; SBMLDocument *doc; SBMLErrorLog *log = getErrorLog(); if (writeDocument) { char* sbmlString = writeSBMLToString(getDocument()); log->clearLog(); doc = readSBMLFromString(sbmlString); free (sbmlString); } else { doc = getDocument(); } /* calls each specified validator in turn * - stopping when errors are encountered */ if (id) { id_validator.init(); nerrors = id_validator.validate(*doc); if (nerrors > 0) { unsigned int origNum = log->getNumErrors(); log->add( id_validator.getFailures() ); if (origNum > 0 && log->contains(InvalidUnitIdSyntax) == true) { /* do not log dangling ref */ while (log->contains(DanglingUnitSIdRef) == true) { log->remove(DanglingUnitSIdRef); nerrors--; } total_errors += nerrors; if (nerrors > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } else if (log->contains(DanglingUnitSIdRef) == false) { total_errors += nerrors; if (writeDocument) SBMLDocument_free(doc); return total_errors; } else { bool onlyDangRef = true; for (unsigned int a = 0; a < log->getNumErrors(); a++) { if (log->getError(a)->getErrorId() != DanglingUnitSIdRef) { onlyDangRef = false; break; } } total_errors += nerrors; if (onlyDangRef == false) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } } if (sbml) { validator.init(); nerrors = validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } if (sbo) { sbo_validator.init(); nerrors = sbo_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( sbo_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } if (math) { math_validator.init(); nerrors = math_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( math_validator.getFailures() ); /* at this point bail if any problems * unit checks may crash if there have been math errors/warnings */ if (writeDocument) SBMLDocument_free(doc); return total_errors; } } if (units) { unit_validator.init(); nerrors = unit_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( unit_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } /* do not even try if there have been unit warnings * changed this as would have bailed */ if (over) { over_validator.init(); nerrors = over_validator.validate(*doc); total_errors += nerrors; if (nerrors > 0) { log->add( over_validator.getFailures() ); /* only want to bail if errors not warnings */ if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0) { if (writeDocument) SBMLDocument_free(doc); return total_errors; } } } if (practice) { practice_validator.init(); nerrors = practice_validator.validate(*doc); if (nerrors > 0) { unsigned int errorsAdded = 0; const std::list<SBMLError> practiceErrors = practice_validator.getFailures(); list<SBMLError>::const_iterator end = practiceErrors.end(); list<SBMLError>::const_iterator iter; for (iter = practiceErrors.begin(); iter != end; ++iter) { if (SBMLError(*iter).getErrorId() != 80701) { log->add( SBMLError(*iter) ); errorsAdded++; } else { if (units) { log->add( SBMLError(*iter) ); errorsAdded++; } } } total_errors += errorsAdded; } } if (writeDocument) SBMLDocument_free(doc); return total_errors; }
/* * Reads the expected attributes into the member data variables */ void Uncertainty::readAttributes(const XMLAttributes& attributes, const ExpectedAttributes& expectedAttributes) { unsigned int level = getLevel(); unsigned int version = getVersion(); unsigned int pkgVersion = getPackageVersion(); unsigned int numErrs; bool assigned = false; SBMLErrorLog* log = getErrorLog(); SBase::readAttributes(attributes, expectedAttributes); numErrs = log->getNumErrors(); for (int n = numErrs-1; n >= 0; n--) { if (log->getError(n)->getErrorId() == UnknownPackageAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownPackageAttribute); log->logPackageError("distrib", DistribUncertaintyAllowedAttributes, pkgVersion, level, version, details); } else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) { const std::string details = log->getError(n)->getMessage(); log->remove(UnknownCoreAttribute); log->logPackageError("distrib", DistribUncertaintyAllowedCoreAttributes, pkgVersion, level, version, details); } } // // id SId (use = "optional" ) // assigned = attributes.readInto("id", mId); if (assigned == true) { if (mId.empty() == true) { logEmptyString(mId, level, version, "<Uncertainty>"); } else if (SyntaxChecker::isValidSBMLSId(mId) == false) { logError(DistribIdSyntaxRule, level, version, "The id '" + mId + "' does " "not conform to the syntax."); } } // // name string (use = "optional" ) // assigned = attributes.readInto("name", mName); if (assigned == true) { if (mName.empty() == true) { logEmptyString(mName, level, version, "<Uncertainty>"); } } }