Example of creating a custom validator to be called during validation.
#include <iostream>
using namespace std;
LIBSBML_CPP_NAMESPACE_USE
{
public:
virtual SBMLValidator* clone()
const {
return new MyCustomValidator(*
this); }
virtual unsigned int validate() {
if (getDocument() == NULL || getModel() == NULL)
return 0;
if (getModel()->getNumReactions() == 0 && getModel()->getNumRules() == 0)
return 0;
unsigned int numErrors = 0;
for (unsigned int i = 0; i < getModel()->getNumRules(); i++)
{
"This model uses algebraic rules, however this application does not support them.",
0, 0,
));
numErrors++;
}
}
for (unsigned int i = 0; i < getModel()->getNumReactions(); i++)
{
if (getModel()->getReaction(i)->isSetFast() &&
getModel()->getReaction(i)->getFast()) {
"This model uses fast reactions, however this application does not support them.",
0, 0,
));
numErrors++;
}
}
return numErrors;
}
};
int
main (int argc, char *argv[])
{
if (argc != 2)
{
cout << endl << "Usage: addCustomValidator filename" << endl << endl;
return 1;
}
const char* filename = argv[1];
MyCustomValidator* myCustomValidator = new MyCustomValidator();
document->addValidator(myCustomValidator);
delete myCustomValidator;
delete document;
return numErrors;
}
@ LIBSBML_CAT_SBML
Definition: SBMLError.h:940
SBMLDocument_t * readSBML(const char *filename)
Reads an SBML document from the given file.
@ SBML_ALGEBRAIC_RULE
Definition: SBMLTypeCodes.h:85
Include all SBML types in a single header file.
Definition of SBMLValidator, the base class for user callable SBML validators.
@ LIBSBML_SEV_WARNING
Definition: XMLError.h:529
Definition: SBMLDocument.h:349
unsigned int checkConsistency()
Performs consistency checking and validation on this SBML document.
Definition: SBMLDocument.cpp:699
void printErrors(std::ostream &stream=std::cerr) const
Prints all the errors or warnings encountered trying to parse, check, or translate this SBML document...
Definition: SBMLDocument.cpp:1186
Definition: SBMLError.h:1097
Definition: SBMLValidator.h:96