本文整理汇总了C++中SBMLErrorLog类的典型用法代码示例。如果您正苦于以下问题:C++ SBMLErrorLog类的具体用法?C++ SBMLErrorLog怎么用?C++ SBMLErrorLog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SBMLErrorLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getErrorLog
/*
* 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());
}
}
示例2: readSBMLFromString
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;
}
示例3: hasActualErrors
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;
}
示例4:
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;
}
示例5: START_TEST
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;
}
示例6: validateSBML
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();
}
示例7: getLevel
/*
* 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);
}
示例8: getPrefix
/** @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;
}
示例9: checkBooleans
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");
}
}
示例10: getParentSBMLObject
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());
}
}
示例11: xos
/*
* 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;
}
示例12: CheckAndAddSBMLIfGood
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;
}
示例13: START_TEST
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);
}
示例14: getSBMLDocument
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;
//.........这里部分代码省略.........
示例15: new
//.........这里部分代码省略.........
* 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;
}