diff --git a/CMakeLists.txt b/CMakeLists.txt index 763b5a1589..ce7347fd21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,6 +175,7 @@ set (LIBSBML_FIND_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/FindLIBSBML. # Whether to compile examples option(WITH_EXAMPLES "Compile the libSBML example programs." OFF) +option(WITH_CHECK "Enable testing of libSBML." OFF) # Which language bindings should be built option(WITH_CSHARP "Generate the C# language interface for libSBML." OFF) diff --git a/CMakeModules/FindBZ2.cmake b/CMakeModules/FindBZ2.cmake index b558240bd9..c93e3db9bd 100644 --- a/CMakeModules/FindBZ2.cmake +++ b/CMakeModules/FindBZ2.cmake @@ -1,3 +1,5 @@ +include(CheckLibraryExists) + string(TOUPPER ${PROJECT_NAME} _UPPER_PROJECT_NAME) set(_PROJECT_DEPENDENCY_DIR ${_UPPER_PROJECT_NAME}_DEPENDENCY_DIR) diff --git a/CMakeModules/FindLIBXML.cmake b/CMakeModules/FindLIBXML.cmake index 73e5f5ae78..1796ec2af1 100644 --- a/CMakeModules/FindLIBXML.cmake +++ b/CMakeModules/FindLIBXML.cmake @@ -1,4 +1,5 @@ include(CheckLibraryExists) +include(CheckCSourceCompiles) string(TOUPPER ${PROJECT_NAME} _UPPER_PROJECT_NAME) set(_PROJECT_DEPENDENCY_DIR ${_UPPER_PROJECT_NAME}_DEPENDENCY_DIR) diff --git a/NEWS.txt b/NEWS.txt index 3cf55ed2ff..fd54af1c12 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -1,7 +1,42 @@  libSBML NEWS -- History of user-visible changes ==================================================================== -5.20.0 +5.20.2 +==================================================================== + +This is mostly a bug fix release enhancing stability when validating +and converting models. + +* New features / improvements + + - Access to error logs from the C API + + - Attributes of the ModelHistory can now be accessed from + const objects. + + - The FBC V3 package has been updated to reflect the latest + specification. There are now optional attributes `fbc:reaction2` + on the FluxObjective and `fbc:variable2` on the + UserDefinedConstraintComponent. + +* Bug fixes + + - A bug converting / validating models with the 'comp' package + has been fixed. + + - A crash when inferring units has been resolved. + + - A fix to the CMake Build system ensures that check for dependencies + is more robust. Thanks to first time contributor @adelhpour + + - The type of the FBC V3 `coefficient` attribute on the + UserDefinedConstraintComponent has been corrected, it was mistakenly + a double before, now it has been corrected to be a SIdRef as + described in the specification. + + +==================================================================== +5.20.0 (2023-04-03) ==================================================================== Given the length of time since our last release the list of changes diff --git a/VERSION.txt b/VERSION.txt index 0af471c5ca..04f1647095 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.20.0 +5.20.2 diff --git a/configure b/configure index 3a3ba31732..1c89d1566a 100755 --- a/configure +++ b/configure @@ -1,7 +1,7 @@ #! /bin/sh # From configure.ac Revision. # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.71 for libSBML 5.20.0. +# Generated by GNU Autoconf 2.71 for libSBML 5.20.2. # # Report bugs to . # @@ -766,8 +766,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='libSBML' PACKAGE_TARNAME='libsbml' -PACKAGE_VERSION='5.20.0' -PACKAGE_STRING='libSBML 5.20.0' +PACKAGE_VERSION='5.20.2' +PACKAGE_STRING='libSBML 5.20.2' PACKAGE_BUGREPORT='libsbml-team@googlegroups.com' PACKAGE_URL='http://sbml.org/Software/libSBML' @@ -1662,7 +1662,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libSBML 5.20.0 to adapt to many kinds of systems. +\`configure' configures libSBML 5.20.2 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1728,7 +1728,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libSBML 5.20.0:";; + short | recursive ) echo "Configuration of libSBML 5.20.2:";; esac cat <<\_ACEOF @@ -1885,7 +1885,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libSBML configure 5.20.0 +libSBML configure 5.20.2 generated by GNU Autoconf 2.71 Copyright (C) 2021 Free Software Foundation, Inc. @@ -2484,7 +2484,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libSBML $as_me 5.20.0, which was +It was created by libSBML $as_me 5.20.2, which was generated by GNU Autoconf 2.71. Invocation command line was $ $0$ac_configure_args_raw @@ -3469,7 +3469,7 @@ ac_config_headers="$ac_config_headers src/sbml/common/libsbml-package.h" ac_config_headers="$ac_config_headers src/sbml/common/libsbml-namespace.h" -LIBSBML_VERSION_NUMERIC=52000 +LIBSBML_VERSION_NUMERIC=52002 @@ -28902,7 +28902,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libSBML $as_me 5.20.0, which was +This file was extended by libSBML $as_me 5.20.2, which was generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -28967,7 +28967,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -libSBML config.status 5.20.0 +libSBML config.status 5.20.2 configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" diff --git a/dev/packages/deviser-fbc_v3.xml b/dev/packages/deviser-fbc_v3.xml index 3b389757a7..c820afefae 100644 --- a/dev/packages/deviser-fbc_v3.xml +++ b/dev/packages/deviser-fbc_v3.xml @@ -168,6 +168,7 @@ + @@ -226,8 +227,9 @@ - + + diff --git a/src/bindings/matlab/getDefaultValues.m b/src/bindings/matlab/getDefaultValues.m index 19d12aeb21..8aca17d09a 100644 --- a/src/bindings/matlab/getDefaultValues.m +++ b/src/bindings/matlab/getDefaultValues.m @@ -3330,6 +3330,7 @@ '', ... '', ... '', ... + '', ... 0/0, ... int32(0), ... '', ... @@ -3337,7 +3338,7 @@ int32(version), ... int32(3), ... }; - nNumberFields = 15; + nNumberFields = 16; end end end @@ -3565,8 +3566,8 @@ int32(-1), ... '', ... '', ... - 0/0, ... - int32(0), ... + '', ... + '', ... '', ... '', ... int32(3), ... diff --git a/src/bindings/matlab/getStructureEnum.m b/src/bindings/matlab/getStructureEnum.m index ae04b5705d..4bf2e3e058 100644 --- a/src/bindings/matlab/getStructureEnum.m +++ b/src/bindings/matlab/getStructureEnum.m @@ -3005,6 +3005,7 @@ {'fbc_id', 'id', 'fbc', 1, 20}, ... {'fbc_name', 'name', 'fbc', 1, 20}, ... {'fbc_reaction', 'reaction', 'fbc', 1, 20}, ... + {'fbc_reaction2', 'reaction2', 'fbc', 1, 20}, ... {'fbc_coefficient', 'coefficient', 'fbc', 1, 20}, ... {'isSetfbc_coefficient', 'coefficient', 'fbc', 0, 7}, ... {'fbc_variableType', 'variableType', 'fbc', 1, 20}, ... @@ -3012,7 +3013,7 @@ {'version', '', '', 0, 0}, ... {'fbc_version', 'version', 'fbc', 1, 20}, ... }; - nNumberFields = 15; + nNumberFields = 16; end end end @@ -3241,8 +3242,8 @@ {'fbc_id', 'id', 'fbc', 1, 20}, ... {'fbc_name', 'name', 'fbc', 1, 20}, ... {'fbc_coefficient', 'coefficient', 'fbc', 1, 20}, ... - {'isSetfbc_coefficient', 'coefficient', 'fbc', 0, 7}, ... {'fbc_variable', 'variable', 'fbc', 1, 20}, ... + {'fbc_variable2', 'variable2', 'fbc', 1, 20}, ... {'fbc_variableType', 'variableType', 'fbc', 1, 20}, ... {'level', '', '', 0, 0}, ... {'version', '', '', 0, 0}, ... diff --git a/src/bindings/matlab/getStructureFieldnames.m b/src/bindings/matlab/getStructureFieldnames.m index 209fab1667..7a7e415b6c 100644 --- a/src/bindings/matlab/getStructureFieldnames.m +++ b/src/bindings/matlab/getStructureFieldnames.m @@ -3382,6 +3382,7 @@ 'fbc_id', ... 'fbc_name', ... 'fbc_reaction', ... + 'fbc_reaction2', ... 'fbc_coefficient', ... 'isSetfbc_coefficient', ... 'fbc_variableType', ... @@ -3389,7 +3390,7 @@ 'version', ... 'fbc_version', ... }; - nNumberFields = 15; + nNumberFields = 16; end end end @@ -3618,8 +3619,8 @@ 'fbc_id', ... 'fbc_name', ... 'fbc_coefficient', ... - 'isSetfbc_coefficient', ... 'fbc_variable', ... + 'fbc_variable2', ... 'fbc_variableType', ... 'level', ... 'version', ... diff --git a/src/bindings/matlab/getValueType.m b/src/bindings/matlab/getValueType.m index 68b4f3be77..2b92671b9c 100644 --- a/src/bindings/matlab/getValueType.m +++ b/src/bindings/matlab/getValueType.m @@ -3333,6 +3333,7 @@ 'char', ... 'char', ... 'char', ... + 'char', ... 'double', ... 'bool', ... 'char', ... @@ -3340,7 +3341,7 @@ 'uint', ... 'uint', ... }; - nNumberFields = 15; + nNumberFields = 16; end end end @@ -3568,8 +3569,8 @@ 'int', ... 'char', ... 'char', ... - 'double', ... - 'bool', ... + 'char', ... + 'char', ... 'char', ... 'char', ... 'uint', ... diff --git a/src/bindings/matlab/test/test-data/fbcV3.xml b/src/bindings/matlab/test/test-data/fbcV3.xml index 2f34912ec4..eb2bb29874 100644 --- a/src/bindings/matlab/test/test-data/fbcV3.xml +++ b/src/bindings/matlab/test/test-data/fbcV3.xml @@ -75,7 +75,7 @@ - + diff --git a/src/bindings/matlab/test/testReadFromFileFbc2.m b/src/bindings/matlab/test/testReadFromFileFbc2.m index 36ce6b9a95..7745db8979 100644 --- a/src/bindings/matlab/test/testReadFromFileFbc2.m +++ b/src/bindings/matlab/test/testReadFromFileFbc2.m @@ -80,7 +80,7 @@ Totalfail = Totalfail + fail_unless( strcmp(m.fbc_objective(1).fbc_fluxObjective(1).typecode, 'SBML_FBC_FLUXOBJECTIVE')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_objective(1).fbc_fluxObjective(1).fbc_reaction, 'R1')); Totalfail = Totalfail + fail_unless( m.fbc_objective(1).fbc_fluxObjective(1).fbc_coefficient == 1); - Totalfail = Totalfail + fail_unless( m.fbc_objective(1).fbc_fluxObjective(1).isSetfbc_coefficient == 1); + Totalfail = Totalfail + fail_unless( strcmp(m.fbc_activeObjective, 'c')); diff --git a/src/bindings/matlab/test/testReadFromFileFbc3.m b/src/bindings/matlab/test/testReadFromFileFbc3.m index c6cf6ea452..10cde3ee15 100644 --- a/src/bindings/matlab/test/testReadFromFileFbc3.m +++ b/src/bindings/matlab/test/testReadFromFileFbc3.m @@ -51,7 +51,7 @@ Totalfail = Totalfail + fail_unless( strcmp(m.fbc_objective(1).fbc_fluxObjective(1).typecode, 'SBML_FBC_FLUXOBJECTIVE')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_objective(1).fbc_fluxObjective(1).fbc_reaction, 'R1')); Totalfail = Totalfail + fail_unless( m.fbc_objective(1).fbc_fluxObjective(1).fbc_coefficient == 1); - Totalfail = Totalfail + fail_unless( m.fbc_objective(1).fbc_fluxObjective(1).isSetfbc_coefficient == 1); + Totalfail = Totalfail + fail_unless( strcmp(m.fbc_activeObjective, 'c')); @@ -77,8 +77,8 @@ Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).typecode, 'SBML_FBC_USERDEFINEDCONSTRAINTCOMPONENT')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_id, 'dd')); - Totalfail = Totalfail + fail_unless( m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_coefficient == 2); - Totalfail = Totalfail + fail_unless( m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).isSetfbc_coefficient == 1); + + Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_coefficient, 'uc2ub')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_variable, 'R2')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_variableType, 'linear')); diff --git a/src/sbml/AlgebraicRule.cpp b/src/sbml/AlgebraicRule.cpp index 4c138cc3f8..66fa21c584 100644 --- a/src/sbml/AlgebraicRule.cpp +++ b/src/sbml/AlgebraicRule.cpp @@ -371,7 +371,7 @@ AlgebraicRule_create(unsigned int level, unsigned int version) AlgebraicRule* obj = new AlgebraicRule(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -387,7 +387,7 @@ AlgebraicRule_createWithNS (SBMLNamespaces_t* sbmlns) AlgebraicRule* obj = new AlgebraicRule(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/AssignmentRule.cpp b/src/sbml/AssignmentRule.cpp index 80e6d4da34..2df28d70d2 100644 --- a/src/sbml/AssignmentRule.cpp +++ b/src/sbml/AssignmentRule.cpp @@ -450,7 +450,7 @@ AssignmentRule_create(unsigned int level, unsigned int version) AssignmentRule* obj = new AssignmentRule(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -466,7 +466,7 @@ AssignmentRule_createWithNS (SBMLNamespaces_t* sbmlns) AssignmentRule* obj = new AssignmentRule(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Compartment.cpp b/src/sbml/Compartment.cpp index 0fe72009fa..1dc5aadb76 100644 --- a/src/sbml/Compartment.cpp +++ b/src/sbml/Compartment.cpp @@ -1999,7 +1999,7 @@ ListOfCompartments::createObject (XMLInputStream& stream) { object = new Compartment(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Compartment(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2029,7 +2029,7 @@ Compartment_create (unsigned int level, unsigned int version) Compartment* obj = new Compartment(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2045,7 +2045,7 @@ Compartment_createWithNS (SBMLNamespaces_t* sbmlns) Compartment* obj = new Compartment(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/CompartmentType.cpp b/src/sbml/CompartmentType.cpp index ed6c114b80..3544a5c21b 100644 --- a/src/sbml/CompartmentType.cpp +++ b/src/sbml/CompartmentType.cpp @@ -807,7 +807,7 @@ ListOfCompartmentTypes::createObject (XMLInputStream& stream) { object = new CompartmentType(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { // compartment type does not exist in L3 object = new CompartmentType(2,4); @@ -837,7 +837,7 @@ CompartmentType_create (unsigned int level, unsigned int version) CompartmentType* obj = new CompartmentType(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -853,7 +853,7 @@ CompartmentType_createWithNS (SBMLNamespaces_t* sbmlns) CompartmentType* obj = new CompartmentType(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Constraint.cpp b/src/sbml/Constraint.cpp index 7aa649e9f7..976b8fa739 100644 --- a/src/sbml/Constraint.cpp +++ b/src/sbml/Constraint.cpp @@ -1076,7 +1076,7 @@ ListOfConstraints::createObject (XMLInputStream& stream) { object = new Constraint(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Constraint(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1107,7 +1107,7 @@ Constraint_create (unsigned int level, unsigned int version) Constraint* obj = new Constraint(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1123,7 +1123,7 @@ Constraint_createWithNS (SBMLNamespaces_t* sbmlns) Constraint* obj = new Constraint(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Delay.cpp b/src/sbml/Delay.cpp index 30e10bc74e..4cdd137973 100644 --- a/src/sbml/Delay.cpp +++ b/src/sbml/Delay.cpp @@ -856,7 +856,7 @@ Delay_create (unsigned int level, unsigned int version) Delay* obj = new Delay(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -872,7 +872,7 @@ Delay_createWithNS (SBMLNamespaces_t* sbmlns) Delay* obj = new Delay(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Event.cpp b/src/sbml/Event.cpp index 410b457af8..d9ec624b00 100644 --- a/src/sbml/Event.cpp +++ b/src/sbml/Event.cpp @@ -1281,7 +1281,7 @@ Event::createObject (XMLInputStream& stream) { mTrigger = new Trigger(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { mTrigger = new Trigger(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1310,7 +1310,7 @@ Event::createObject (XMLInputStream& stream) { mDelay = new Delay(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { mDelay = new Delay(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1341,7 +1341,7 @@ Event::createObject (XMLInputStream& stream) { mPriority = new Priority(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { mPriority = new Priority(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2293,7 +2293,7 @@ ListOfEvents::createObject (XMLInputStream& stream) { object = new Event(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Event(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2324,7 +2324,7 @@ Event_create (unsigned int level, unsigned int version) Event* obj = new Event(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2340,7 +2340,7 @@ Event_createWithNS (SBMLNamespaces_t* sbmlns) Event* obj = new Event(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/EventAssignment.cpp b/src/sbml/EventAssignment.cpp index 12e87137f0..21835f1a10 100644 --- a/src/sbml/EventAssignment.cpp +++ b/src/sbml/EventAssignment.cpp @@ -1212,7 +1212,7 @@ ListOfEventAssignments::createObject (XMLInputStream& stream) { object = new EventAssignment(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new EventAssignment(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1243,7 +1243,7 @@ EventAssignment_create (unsigned int level, unsigned int version) EventAssignment* obj = new EventAssignment(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1259,7 +1259,7 @@ EventAssignment_createWithNS (SBMLNamespaces_t* sbmlns) EventAssignment* obj = new EventAssignment(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/FunctionDefinition.cpp b/src/sbml/FunctionDefinition.cpp index b6a3721407..f155fe023e 100644 --- a/src/sbml/FunctionDefinition.cpp +++ b/src/sbml/FunctionDefinition.cpp @@ -1292,7 +1292,7 @@ ListOfFunctionDefinitions::createObject (XMLInputStream& stream) { object = new FunctionDefinition(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new FunctionDefinition(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1322,7 +1322,7 @@ FunctionDefinition_create (unsigned int level, unsigned int version) FunctionDefinition* obj = new FunctionDefinition(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1338,7 +1338,7 @@ FunctionDefinition_createWithNS (SBMLNamespaces_t* sbmlns) FunctionDefinition* obj = new FunctionDefinition(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/InitialAssignment.cpp b/src/sbml/InitialAssignment.cpp index 21e5ac13d2..9d4c2bf111 100644 --- a/src/sbml/InitialAssignment.cpp +++ b/src/sbml/InitialAssignment.cpp @@ -1194,7 +1194,7 @@ ListOfInitialAssignments::createObject (XMLInputStream& stream) { object = new InitialAssignment(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new InitialAssignment(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1225,7 +1225,7 @@ InitialAssignment_create (unsigned int level, unsigned int version) InitialAssignment* obj = new InitialAssignment(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1241,7 +1241,7 @@ InitialAssignment_createWithNS (SBMLNamespaces_t* sbmlns) InitialAssignment* obj = new InitialAssignment(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/KineticLaw.cpp b/src/sbml/KineticLaw.cpp index b455641b34..61f0c9f7fe 100644 --- a/src/sbml/KineticLaw.cpp +++ b/src/sbml/KineticLaw.cpp @@ -2007,7 +2007,7 @@ KineticLaw_create (unsigned int level, unsigned int version) KineticLaw* obj = new KineticLaw(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2023,7 +2023,7 @@ KineticLaw_createWithNS (SBMLNamespaces_t* sbmlns) KineticLaw* obj = new KineticLaw(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/LocalParameter.cpp b/src/sbml/LocalParameter.cpp index b28b9c7928..fb61f5bbac 100644 --- a/src/sbml/LocalParameter.cpp +++ b/src/sbml/LocalParameter.cpp @@ -752,7 +752,7 @@ ListOfLocalParameters::createObject (XMLInputStream& stream) { object = new LocalParameter(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new LocalParameter(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -782,7 +782,7 @@ LocalParameter_create (unsigned int level, unsigned int version) LocalParameter* obj = new LocalParameter(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -798,7 +798,7 @@ LocalParameter_createWithNS (SBMLNamespaces_t* sbmlns) LocalParameter* obj = new LocalParameter(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Model.cpp b/src/sbml/Model.cpp index 9a8d716d04..61320577a5 100644 --- a/src/sbml/Model.cpp +++ b/src/sbml/Model.cpp @@ -7104,7 +7104,7 @@ Model_create (unsigned int level, unsigned int version) Model* obj = new Model(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -7120,7 +7120,7 @@ Model_createWithNS (SBMLNamespaces_t* sbmlns) Model* obj = new Model(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Model.h b/src/sbml/Model.h index 061b303687..57c694d2fb 100644 --- a/src/sbml/Model.h +++ b/src/sbml/Model.h @@ -4123,6 +4123,14 @@ class LIBSBML_EXTERN Model : public SBase /** @endcond */ + /** @cond doxygenLibsbmlInternal */ + /* + * Clears the list of FormulaUnitsData object in this Model. + */ + void removeListFormulaUnitsData(); + /** @endcond */ + + protected: /** @cond doxygenLibsbmlInternal */ @@ -4249,12 +4257,6 @@ class LIBSBML_EXTERN Model : public SBase void createSpeciesReferenceUnitsData(SpeciesReference* sr, UnitFormulaFormatter* unitFormatter); - /* - * Clears the list of FormulaUnitsData object in this Model. - */ - void removeListFormulaUnitsData(); - - /* * creates the substance units data item */ diff --git a/src/sbml/ModifierSpeciesReference.cpp b/src/sbml/ModifierSpeciesReference.cpp index 79d386f8ad..c6cc200e24 100644 --- a/src/sbml/ModifierSpeciesReference.cpp +++ b/src/sbml/ModifierSpeciesReference.cpp @@ -397,7 +397,7 @@ ModifierSpeciesReference_create(unsigned int level, unsigned int version) ModifierSpeciesReference* obj = new ModifierSpeciesReference(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -413,7 +413,7 @@ ModifierSpeciesReference_createWithNS (SBMLNamespaces_t* sbmlns) ModifierSpeciesReference* obj = new ModifierSpeciesReference(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Parameter.cpp b/src/sbml/Parameter.cpp index 1ccb891725..82aa9877a8 100644 --- a/src/sbml/Parameter.cpp +++ b/src/sbml/Parameter.cpp @@ -1918,7 +1918,7 @@ ListOfParameters::createObject (XMLInputStream& stream) { object = new Parameter(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Parameter(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1948,7 +1948,7 @@ Parameter_create (unsigned int level, unsigned int version) Parameter* obj = new Parameter(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1964,7 +1964,7 @@ Parameter_createWithNS (SBMLNamespaces_t* sbmlns) Parameter* obj = new Parameter(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Priority.cpp b/src/sbml/Priority.cpp index 6608991124..02c7b9b28b 100644 --- a/src/sbml/Priority.cpp +++ b/src/sbml/Priority.cpp @@ -703,7 +703,7 @@ Priority_create (unsigned int level, unsigned int version) Priority* obj = new Priority(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -719,7 +719,7 @@ Priority_createWithNS (SBMLNamespaces_t* sbmlns) Priority* obj = new Priority(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/RateRule.cpp b/src/sbml/RateRule.cpp index 31edb73ab7..8cf7e60314 100644 --- a/src/sbml/RateRule.cpp +++ b/src/sbml/RateRule.cpp @@ -449,7 +449,7 @@ RateRule_create(unsigned int level, unsigned int version) RateRule* obj = new RateRule(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -465,7 +465,7 @@ RateRule_createWithNS (SBMLNamespaces_t* sbmlns) RateRule* obj = new RateRule(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Reaction.cpp b/src/sbml/Reaction.cpp index 815697ef58..8dfcfa4d51 100644 --- a/src/sbml/Reaction.cpp +++ b/src/sbml/Reaction.cpp @@ -1564,7 +1564,7 @@ Reaction::createObject (XMLInputStream& stream) { mKineticLaw = new KineticLaw(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { mKineticLaw = new KineticLaw(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2599,7 +2599,7 @@ ListOfReactions::createObject (XMLInputStream& stream) { object = new Reaction(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Reaction(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2630,7 +2630,7 @@ Reaction_create (unsigned int level, unsigned int version) Reaction* obj = new Reaction(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2646,7 +2646,7 @@ Reaction_createWithNS (SBMLNamespaces_t* sbmlns) Reaction* obj = new Reaction(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Rule.cpp b/src/sbml/Rule.cpp index 2ce36e5b9f..0713f612db 100644 --- a/src/sbml/Rule.cpp +++ b/src/sbml/Rule.cpp @@ -1755,7 +1755,7 @@ ListOfRules::createObject (XMLInputStream& stream) { object = new AlgebraicRule(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new AlgebraicRule(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1777,7 +1777,7 @@ ListOfRules::createObject (XMLInputStream& stream) { object = new AssignmentRule(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new AssignmentRule(1, 2); } @@ -1792,7 +1792,7 @@ ListOfRules::createObject (XMLInputStream& stream) { object = new RateRule(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new RateRule(1, 2); } @@ -1832,7 +1832,7 @@ ListOfRules::createObject (XMLInputStream& stream) { object = new AssignmentRule(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new AssignmentRule(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1849,7 +1849,7 @@ ListOfRules::createObject (XMLInputStream& stream) { object = new RateRule(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new RateRule(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1880,7 +1880,7 @@ Rule_createAlgebraic (unsigned int level, unsigned int version) AlgebraicRule* obj = new AlgebraicRule(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1896,7 +1896,7 @@ Rule_createAlgebraicWithNS (SBMLNamespaces_t* sbmlns) AlgebraicRule* obj = new AlgebraicRule(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1912,7 +1912,7 @@ Rule_createAssignment (unsigned int level, unsigned int version) AssignmentRule* obj = new AssignmentRule(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1928,7 +1928,7 @@ Rule_createAssignmentWithNS (SBMLNamespaces_t* sbmlns) AssignmentRule* obj = new AssignmentRule(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1944,7 +1944,7 @@ Rule_createRate (unsigned int level, unsigned int version) RateRule* obj = new RateRule(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1960,7 +1960,7 @@ Rule_createRateWithNS (SBMLNamespaces_t* sbmlns) RateRule* obj = new RateRule(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/SBMLDocument.cpp b/src/sbml/SBMLDocument.cpp index ce152caa12..5b9995abe3 100644 --- a/src/sbml/SBMLDocument.cpp +++ b/src/sbml/SBMLDocument.cpp @@ -633,7 +633,7 @@ SBMLDocument::createModel (const std::string sid) { mModel = new Model(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { /* here we do not create a default object as the level/version must * match the parent object @@ -828,6 +828,12 @@ unsigned int SBMLDocument::validateSBML () unsigned int numErrors = mInternalValidator->checkConsistency(); + for (unsigned int i = 0; i < getNumPlugins(); i++) + { + numErrors += static_cast + (getPlugin(i))->checkConsistency(); + } + list::iterator it; for (it = mValidators.begin(); it != mValidators.end(); it++) { @@ -1301,7 +1307,7 @@ SBMLDocument::createObject (XMLInputStream& stream) { mModel = new Model(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { mModel = new Model(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2198,7 +2204,7 @@ SBMLDocument_create () SBMLDocument* obj = new SBMLDocument(); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2214,7 +2220,7 @@ SBMLDocument_createWithLevelAndVersion (unsigned int level, unsigned int version SBMLDocument* obj = new SBMLDocument(level, version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2230,7 +2236,7 @@ SBMLDocument_createWithSBMLNamespaces (SBMLNamespaces_t *sbmlns) SBMLDocument* obj = new SBMLDocument(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2399,6 +2405,11 @@ SBMLDocument_checkConsistency (SBMLDocument_t *d) LIBSBML_EXTERN +unsigned int SBMLDocument_validateSBML(SBMLDocument_t * d) +{ + return (d != NULL) ? d->validateSBML() : SBML_INT_MAX; +} + unsigned int SBMLDocument_checkInternalConsistency (SBMLDocument_t *d) { @@ -2479,6 +2490,13 @@ SBMLDocument_getError (SBMLDocument_t *d, unsigned int n) return (d != NULL) ? d->getError(n) : NULL; } +LIBSBML_EXTERN +const SBMLErrorLog_t * +SBMLDocument_getErrorLog(SBMLDocument_t *d) +{ + return (d != NULL) ? d->getErrorLog() : NULL; +} + LIBSBML_EXTERN const SBMLError_t * SBMLDocument_getErrorWithSeverity(SBMLDocument_t *d, unsigned int n, unsigned int severity) diff --git a/src/sbml/SBMLDocument.h b/src/sbml/SBMLDocument.h index 15b73bf9e2..f94b745317 100644 --- a/src/sbml/SBMLDocument.h +++ b/src/sbml/SBMLDocument.h @@ -2472,8 +2472,8 @@ SBMLDocument_checkL2v2Compatibility (SBMLDocument_t *d); * @memberof SBMLDocument_t */ LIBSBML_EXTERN -unsigned int -SBMLDocument_checkL2v3Compatibility (SBMLDocument_t *d); +unsigned int +SBMLDocument_checkL2v3Compatibility(SBMLDocument_t *d); /** @@ -2588,6 +2588,11 @@ const SBMLError_t * SBMLDocument_getError (SBMLDocument_t *d, unsigned int n); +LIBSBML_EXTERN +const SBMLErrorLog_t * +SBMLDocument_getErrorLog(SBMLDocument_t *d); + + /** * Returns the nth error or warning with the given severity * encountered during parsing, consistency checking, or attempted diff --git a/src/sbml/SBMLErrorLog.cpp b/src/sbml/SBMLErrorLog.cpp index 0d3ba18d51..129ea330d3 100644 --- a/src/sbml/SBMLErrorLog.cpp +++ b/src/sbml/SBMLErrorLog.cpp @@ -417,6 +417,101 @@ SBMLErrorLog::getErrorWithSeverity(unsigned int n, unsigned int severity) const /** @cond doxygenIgnored */ + +LIBSBML_EXTERN +SBMLErrorLog_t* +SBMLErrorLog_create(void) +{ + return new(nothrow) SBMLErrorLog; +} + + +LIBSBML_EXTERN +void +SBMLErrorLog_free(SBMLErrorLog_t* log) +{ + delete log; +} + + +LIBSBML_EXTERN +void +SBMLErrorLog_add(SBMLErrorLog_t *log, const SBMLError_t *error) +{ + if (log == NULL || error == NULL) return; + log->add(*error); +} + + +LIBSBML_EXTERN +const SBMLError_t * +SBMLErrorLog_getError(const SBMLErrorLog_t *log, unsigned int n) +{ + return (log != NULL) ? log->getError(n) : NULL; +} + + +LIBSBML_EXTERN +const SBMLError_t * +SBMLErrorLog_getErrorWithSeverity(const SBMLErrorLog_t *log, unsigned int n, unsigned int severity) +{ + return (log != NULL) ? log->getErrorWithSeverity(n, severity) : NULL; +} + +LIBSBML_EXTERN +unsigned int +SBMLErrorLog_getNumFailsWithSeverity(const SBMLErrorLog_t *log, unsigned int severity) +{ + return (log != NULL) ? log->getNumFailsWithSeverity(severity) : 0; +} + +LIBSBML_EXTERN +unsigned int +SBMLErrorLog_getNumErrors(const SBMLErrorLog_t *log) +{ + return (log != NULL) ? log->getNumErrors() : 0; +} + + +LIBSBML_EXTERN +int +SBMLErrorLog_contains(const SBMLErrorLog_t *log, unsigned int errorId) +{ + return (log != NULL) ? (int)(log->contains(errorId)) : 0; +} + +LIBSBML_EXTERN +void +SBMLErrorLog_remove(SBMLErrorLog_t *log, unsigned int errorId) +{ + if (log != NULL) + { + log->remove(errorId); + } +} + +LIBSBML_EXTERN +void +SBMLErrorLog_removeAll(SBMLErrorLog_t *log, unsigned int errorId) +{ + if (log != NULL) + { + log->removeAll(errorId); + } +} + +LIBSBML_EXTERN +void +SBMLErrorLog_clearLog(SBMLErrorLog_t *log) +{ + if (log != NULL) + { + log->clearLog(); + } +} + + + /** @endcond */ LIBSBML_CPP_NAMESPACE_END diff --git a/src/sbml/SBMLErrorLog.h b/src/sbml/SBMLErrorLog.h index b5017186d4..7e54b30044 100644 --- a/src/sbml/SBMLErrorLog.h +++ b/src/sbml/SBMLErrorLog.h @@ -360,4 +360,185 @@ class LIBSBML_EXTERN SBMLErrorLog : public XMLErrorLog LIBSBML_CPP_NAMESPACE_END #endif /* __cplusplus */ + +#ifndef SWIG + +LIBSBML_CPP_NAMESPACE_BEGIN +BEGIN_C_DECLS + +/** + * Creates a new empty SBMLErrorLog_t structure and returns it. + * + * @return the new SBMLErrorLog_t structure. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +SBMLErrorLog_t* +SBMLErrorLog_create(void); + + +/** + * Frees the SBMLErrorLog_t structure. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +void +SBMLErrorLog_free(SBMLErrorLog_t*); + + +/** + * Logs the given XMLError_t structure. + * + * @param log SBMLErrorLog_t, the error log to be added to. + * @param error XMLError_t, the error to be logged. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +void +SBMLErrorLog_add(SBMLErrorLog_t *log, const SBMLError_t *error); + + +/** + * Returns the nth SBMLError_t in this log. + * + * @param log SBMLErrorLog_t, the error log to be queried. + * @param n unsigned int number of the error to retrieve. + * + * @return the nth SBMLError_t in this log. + * If the index @p n is invalid, @c NULL is returned. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +const SBMLError_t * +SBMLErrorLog_getError(const SBMLErrorLog_t *log, unsigned int n); + + +/** + * Returns the nth SBMLError object with given severity in this log. + * + * Index @p n is counted from 0. Callers should first inquire about the + * number of items in the log by using the + * @if java SBMLErrorLog::getNumFailsWithSeverity(long severity)@else getNumFailsWithSeverity()@endif@~ method. + * Attempts to use an error index number that exceeds the actual number + * of errors in the log will result in a @c NULL being returned. + * + * @param log SBMLErrorLog_t, the error log to be queried. + * @param n the index number of the error to retrieve (with 0 being the + * first error). + * @param severity the severity of the error to retrieve. + * + * @return the nth SBMLError in this log, or @c NULL if @p n is + * greater than or equal to + * @if java SBMLErrorLog::getNumFailsWithSeverity(long severity)@else getNumFailsWithSeverity()@endif. + * + * @see getNumFailsWithSeverity(unsigned int severity) + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +const SBMLError_t * +SBMLErrorLog_getErrorWithSeverity(const SBMLErrorLog_t *log, unsigned int n, unsigned int severity); + + +/** + * Returns the number of errors that have been logged with the given + * severity code. + * + * @copydetails doc_errorlog_what_are_severities + * + * @param log SBMLErrorLog_t, the error log to be queried. + * @if clike @param severity a value from + * #SBMLErrorSeverity_t @endif@if java @param severity a + * value from the set of LIBSBML_SEV_ constants defined by + * the interface class libsbmlConstants @endif@if python @param severity a + * value from the set of LIBSBML_SEV_ constants defined by + * the interface class @link libsbml libsbml@endlink. @endif@~ + * + * @return a count of the number of errors with the given severity code. + * + * @see getNumErrors() + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +unsigned int +SBMLErrorLog_getNumFailsWithSeverity(const SBMLErrorLog_t *log, unsigned int severity); + + +/** + * Returns the number of errors that have been logged. + * + * @param log SBMLErrorLog_t, the error log to be queried. + * + * @return the number of errors that have been logged. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +unsigned int +SBMLErrorLog_getNumErrors(const SBMLErrorLog_t *log); + + +/** + * Returns @c true if SBMLErrorLog contains an errorId + * + * @param log SBMLErrorLog_t, the error log to be queried. + * @param errorId the error identifier of the error to be found. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +int +SBMLErrorLog_contains(const SBMLErrorLog_t *log, unsigned int errorId); + + +/** + * Removes an error having errorId from the SBMLError list. + * + * Only the first item will be removed if there are multiple errors + * with the given errorId. + * + * @param log SBMLErrorLog_t, the error log to be cleared. + * @param errorId the error identifier of the error to be removed. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +void +SBMLErrorLog_remove(SBMLErrorLog_t *log, unsigned int errorId); + + +/** + * Removes all errors having errorId from the SBMLError list. + * + * @param log SBMLErrorLog_t, the error log to be cleared. + * @param errorId the error identifier of the error to be removed. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +void +SBMLErrorLog_removeAll(SBMLErrorLog_t *log, unsigned int errorId); + + +/** + * Removes all errors from this log. + * + * @param log SBMLErrorLog_t, the error log to be cleared. + * + * @memberof SBMLErrorLog_t + */ +LIBSBML_EXTERN +void +SBMLErrorLog_clearLog(SBMLErrorLog_t *log); + +END_C_DECLS +LIBSBML_CPP_NAMESPACE_END + +#endif /* !SWIG */ #endif /* SBMLErrorLog_h */ diff --git a/src/sbml/SBMLWriter.cpp b/src/sbml/SBMLWriter.cpp index b63f946e69..c0a85cd5a5 100644 --- a/src/sbml/SBMLWriter.cpp +++ b/src/sbml/SBMLWriter.cpp @@ -140,91 +140,95 @@ bool SBMLWriter::writeSBML (const SBMLDocument* d, const std::string& filename) { std::ostream* stream = NULL; - - try + if (d == NULL) { - // 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) ) + return false; + } + else + { + try { - 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) ) - ) + // 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)) { - filenameinzip += ".xml"; + 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 = '\\'; + char sepr = '\\'; #else - char sepr = '/'; + char sepr = '/'; #endif - size_t spos = filenameinzip.rfind(sepr, filenameinzip.length() - 1); - if( spos != string::npos ) + 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 { - filenameinzip = filenameinzip.substr(spos + 1, filenameinzip.length() - 1); + stream = new(std::nothrow) std::ofstream(filename.c_str()); } - - - stream = OutputCompressor::openZipOStream(filename, filenameinzip); } - else + catch (ZlibNotLinked&) { - stream = new(std::nothrow) std::ofstream(filename.c_str()); + // libSBML is not linked with zlib. + XMLErrorLog *log = (const_cast(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(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; } - } - catch ( ZlibNotLinked& ) - { - // libSBML is not linked with zlib. - XMLErrorLog *log = (const_cast(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(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(d))->getErrorLog(); - log->logError(XMLFileUnwritable); - delete stream; - return false; + if (stream == NULL || stream->fail() || stream->bad()) + { + SBMLErrorLog *log = (const_cast(d))->getErrorLog(); + log->logError(XMLFileUnwritable); + delete stream; + return false; + } } - bool result = writeSBML(d, *stream); - delete stream; - - return result; + bool result = writeSBML(d, *stream); + delete stream; + return result; } @@ -238,6 +242,10 @@ bool SBMLWriter::writeSBML (const SBMLDocument* d, std::ostream& stream) { bool result = false; + if (d == NULL) + { + return result; + } try { diff --git a/src/sbml/SBase.cpp b/src/sbml/SBase.cpp index 48c45ee316..4e1ada2ac5 100644 --- a/src/sbml/SBase.cpp +++ b/src/sbml/SBase.cpp @@ -1087,7 +1087,7 @@ SBase::getModifiedDate(unsigned int n) unsigned int SBase::getNumModifiedDates() { - return (mHistory != NULL) ? mHistory->getNumModifiedDates() : NULL; + return (mHistory != NULL) ? mHistory->getNumModifiedDates() : 0; } diff --git a/src/sbml/Species.cpp b/src/sbml/Species.cpp index fb7f720647..05d74a69d9 100644 --- a/src/sbml/Species.cpp +++ b/src/sbml/Species.cpp @@ -2545,7 +2545,7 @@ ListOfSpecies::createObject (XMLInputStream& stream) { object = new Species(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Species(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2575,7 +2575,7 @@ Species_create (unsigned int level, unsigned int version) Species* obj = new Species(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2591,7 +2591,7 @@ Species_createWithNS (SBMLNamespaces_t* sbmlns) Species* obj = new Species(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/SpeciesReference.cpp b/src/sbml/SpeciesReference.cpp index 24acd77864..39a9737188 100644 --- a/src/sbml/SpeciesReference.cpp +++ b/src/sbml/SpeciesReference.cpp @@ -539,7 +539,7 @@ SpeciesReference::createStoichiometryMath () { mStoichiometryMath = new StoichiometryMath(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { /* here we do not create a default object as the level/version must * match the parent object @@ -1148,7 +1148,7 @@ SpeciesReference::createObject (XMLInputStream& stream) { mStoichiometryMath = new StoichiometryMath(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { mStoichiometryMath = new StoichiometryMath( SBMLDocument::getDefaultLevel(), @@ -1740,7 +1740,7 @@ ListOfSpeciesReferences::createObject (XMLInputStream& stream) { object = new SpeciesReference(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { object = new SpeciesReference(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1759,7 +1759,7 @@ ListOfSpeciesReferences::createObject (XMLInputStream& stream) { object = new SpeciesReference(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { object = new SpeciesReference(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1775,7 +1775,7 @@ ListOfSpeciesReferences::createObject (XMLInputStream& stream) { object = new ModifierSpeciesReference(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { object = new ModifierSpeciesReference(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1791,7 +1791,7 @@ ListOfSpeciesReferences::createObject (XMLInputStream& stream) { object = new ModifierSpeciesReference(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { object = new ModifierSpeciesReference(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -1818,7 +1818,7 @@ SpeciesReference_create (unsigned int level, unsigned int version) SpeciesReference* obj = new SpeciesReference(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1834,7 +1834,7 @@ SpeciesReference_createWithNS (SBMLNamespaces_t* sbmlns) SpeciesReference* obj = new SpeciesReference(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1850,7 +1850,7 @@ SpeciesReference_createModifier (unsigned int level, unsigned int version) ModifierSpeciesReference* obj = new ModifierSpeciesReference(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -1866,7 +1866,7 @@ SpeciesReference_createModifierWithNS (SBMLNamespaces_t* sbmlns) ModifierSpeciesReference* obj = new ModifierSpeciesReference(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/SpeciesType.cpp b/src/sbml/SpeciesType.cpp index dab5dcc38e..769f76020d 100644 --- a/src/sbml/SpeciesType.cpp +++ b/src/sbml/SpeciesType.cpp @@ -804,7 +804,7 @@ ListOfSpeciesTypes::createObject (XMLInputStream& stream) { object = new SpeciesType(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { // species type does not exist in L3, hence we fall back object = new SpeciesType(2, @@ -836,7 +836,7 @@ SpeciesType_create (unsigned int level, unsigned int version) SpeciesType* obj = new SpeciesType(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -852,7 +852,7 @@ SpeciesType_createWithNS (SBMLNamespaces_t* sbmlns) SpeciesType* obj = new SpeciesType(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/StoichiometryMath.cpp b/src/sbml/StoichiometryMath.cpp index b2663a427b..007a6d469b 100644 --- a/src/sbml/StoichiometryMath.cpp +++ b/src/sbml/StoichiometryMath.cpp @@ -644,7 +644,7 @@ StoichiometryMath_create (unsigned int level, unsigned int version) StoichiometryMath* obj = new StoichiometryMath(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -660,7 +660,7 @@ StoichiometryMath_createWithNS (SBMLNamespaces_t* sbmlns) StoichiometryMath* obj = new StoichiometryMath(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Trigger.cpp b/src/sbml/Trigger.cpp index 3ed4857d33..3410d8413f 100644 --- a/src/sbml/Trigger.cpp +++ b/src/sbml/Trigger.cpp @@ -979,7 +979,7 @@ Trigger_create (unsigned int level, unsigned int version) Trigger* obj = new Trigger(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -995,7 +995,7 @@ Trigger_createWithNS (SBMLNamespaces_t* sbmlns) Trigger* obj = new Trigger(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/Unit.cpp b/src/sbml/Unit.cpp index 56e9c37d91..e6d2ed3b05 100644 --- a/src/sbml/Unit.cpp +++ b/src/sbml/Unit.cpp @@ -2569,7 +2569,7 @@ ListOfUnits::createObject (XMLInputStream& stream) { object = new Unit(getSBMLNamespaces()); } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new Unit(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2599,7 +2599,7 @@ Unit_create (unsigned int level, unsigned int version) Unit* obj = new Unit(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2615,7 +2615,7 @@ Unit_createWithNS (SBMLNamespaces_t* sbmlns) Unit* obj = new Unit(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/UnitDefinition.cpp b/src/sbml/UnitDefinition.cpp index 3852f04289..018e04fb27 100644 --- a/src/sbml/UnitDefinition.cpp +++ b/src/sbml/UnitDefinition.cpp @@ -2310,7 +2310,7 @@ ListOfUnitDefinitions::createObject (XMLInputStream& stream) { object = new UnitDefinition(getSBMLNamespaces()); } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { object = new UnitDefinition(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); @@ -2335,7 +2335,7 @@ UnitDefinition_create (unsigned int level, unsigned int version) UnitDefinition* obj = new UnitDefinition(level,version); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } @@ -2351,7 +2351,7 @@ UnitDefinition_createWithNS (SBMLNamespaces_t* sbmlns) UnitDefinition* obj = new UnitDefinition(sbmlns); return obj; } - catch (SBMLConstructorException) + catch (SBMLConstructorException &) { return NULL; } diff --git a/src/sbml/annotation/Date.h b/src/sbml/annotation/Date.h index 227446b879..31e74424ec 100644 --- a/src/sbml/annotation/Date.h +++ b/src/sbml/annotation/Date.h @@ -316,7 +316,7 @@ class LIBSBML_EXTERN Date * * @return the year from this Date. */ - unsigned int getYear() { return mYear; } + unsigned int getYear() const { return mYear; } /** @@ -324,7 +324,7 @@ class LIBSBML_EXTERN Date * * @return the month from this Date. */ - unsigned int getMonth() { return mMonth; } + unsigned int getMonth() const { return mMonth; } /** @@ -332,7 +332,7 @@ class LIBSBML_EXTERN Date * * @return the day from this Date. */ - unsigned int getDay() { return mDay; } + unsigned int getDay() const { return mDay; } /** @@ -340,7 +340,7 @@ class LIBSBML_EXTERN Date * * @return the hour from this Date. */ - unsigned int getHour() { return mHour; } + unsigned int getHour() const { return mHour; } /** @@ -348,7 +348,7 @@ class LIBSBML_EXTERN Date * * @return the minute from this Date. */ - unsigned int getMinute() { return mMinute; } + unsigned int getMinute() const { return mMinute; } /** @@ -356,7 +356,7 @@ class LIBSBML_EXTERN Date * * @return the seconds from this Date. */ - unsigned int getSecond() { return mSecond; } + unsigned int getSecond() const { return mSecond; } /** @@ -364,7 +364,7 @@ class LIBSBML_EXTERN Date * * @return the sign of the offset from this Date. */ - unsigned int getSignOffset() { return mSignOffset; } + unsigned int getSignOffset() const { return mSignOffset; } /** @@ -372,7 +372,7 @@ class LIBSBML_EXTERN Date * * @return the hours of the offset from this Date. */ - unsigned int getHoursOffset() { return mHoursOffset; } + unsigned int getHoursOffset() const { return mHoursOffset; } /** @@ -380,7 +380,7 @@ class LIBSBML_EXTERN Date * * @return the minutes of the offset from this Date. */ - unsigned int getMinutesOffset() { return mMinutesOffset;} + unsigned int getMinutesOffset() const { return mMinutesOffset;} /** @@ -394,7 +394,7 @@ class LIBSBML_EXTERN Date * * @return the date as a string. */ - const std::string& getDateAsString() { return mDate; } + const std::string& getDateAsString() const { return mDate; } /** diff --git a/src/sbml/annotation/ModelHistory.cpp b/src/sbml/annotation/ModelHistory.cpp index 2af83f7d9a..13229c86f5 100644 --- a/src/sbml/annotation/ModelHistory.cpp +++ b/src/sbml/annotation/ModelHistory.cpp @@ -326,7 +326,7 @@ ModelHistory::getModifiedDate(unsigned int n) * @return number in List of Creator */ unsigned int -ModelHistory::getNumCreators() +ModelHistory::getNumCreators() const { return mCreators != NULL ? mCreators->getSize() : 0; } @@ -336,7 +336,7 @@ ModelHistory::getNumCreators() * @return number in List of modified dates */ unsigned int -ModelHistory::getNumModifiedDates() +ModelHistory::getNumModifiedDates() const { return mModifiedDates->getSize(); } @@ -356,7 +356,7 @@ ModelHistory::getCreator(unsigned int n) * otherwise. */ bool -ModelHistory::isSetCreatedDate() +ModelHistory::isSetCreatedDate() const { return mCreatedDate != NULL; } @@ -367,7 +367,7 @@ ModelHistory::isSetCreatedDate() * otherwise. */ bool -ModelHistory::isSetModifiedDate() +ModelHistory::isSetModifiedDate() const { return (getNumModifiedDates() != 0); } diff --git a/src/sbml/annotation/ModelHistory.h b/src/sbml/annotation/ModelHistory.h index 7944939a4b..313f540294 100644 --- a/src/sbml/annotation/ModelHistory.h +++ b/src/sbml/annotation/ModelHistory.h @@ -206,7 +206,7 @@ class LIBSBML_EXTERN ModelHistory * @return @c true if the creation date value of this ModelHistory is * set, @c false otherwise. */ - bool isSetCreatedDate(); + bool isSetCreatedDate() const; /** @@ -216,7 +216,7 @@ class LIBSBML_EXTERN ModelHistory * @return @c true if the modification date value of this ModelHistory * object is set, @c false otherwise. */ - bool isSetModifiedDate(); + bool isSetModifiedDate() const; /** @@ -302,7 +302,7 @@ class LIBSBML_EXTERN ModelHistory * * @return the number of ModifiedDates in this ModelHistory. */ - unsigned int getNumModifiedDates(); + unsigned int getNumModifiedDates() const; /** @@ -358,7 +358,7 @@ class LIBSBML_EXTERN ModelHistory * * @return the number of ModelCreators objects. */ - unsigned int getNumCreators(); + unsigned int getNumCreators() const; /** diff --git a/src/sbml/common/libsbml-version.h b/src/sbml/common/libsbml-version.h index 79e51dfaaf..10c351a8f0 100644 --- a/src/sbml/common/libsbml-version.h +++ b/src/sbml/common/libsbml-version.h @@ -51,7 +51,7 @@ * * A version string of the form "1.2.3". */ -#define LIBSBML_DOTTED_VERSION "5.20.0" +#define LIBSBML_DOTTED_VERSION "5.20.2" /** @@ -62,7 +62,7 @@ * libSBML is released, making it easy to use less-than and greater-than * comparisons when testing versions numbers. */ -#define LIBSBML_VERSION 52000 +#define LIBSBML_VERSION 52002 /** @@ -70,7 +70,7 @@ * * The numeric version as a string: version 1.2.3 becomes "10203". */ -#define LIBSBML_VERSION_STRING "52000" +#define LIBSBML_VERSION_STRING "52002" LIBSBML_CPP_NAMESPACE_BEGIN diff --git a/src/sbml/common/sbmlfwd.h b/src/sbml/common/sbmlfwd.h index d6ade0f637..6118859c03 100644 --- a/src/sbml/common/sbmlfwd.h +++ b/src/sbml/common/sbmlfwd.h @@ -256,6 +256,12 @@ typedef CLASS_OR_STRUCT SBMLWriter SBMLWriter_t; */ typedef CLASS_OR_STRUCT SBMLError SBMLError_t; +/** +* @var typedef class SBMLErrorLog SBMLErrorLog_t +* @copydoc SBMLErrorLog +*/ +typedef CLASS_OR_STRUCT SBMLErrorLog SBMLErrorLog_t; + /** * @var typedef class ASTNode ASTNode_t * @copydoc ASTNode diff --git a/src/sbml/conversion/SBMLLevelVersionConverter.cpp b/src/sbml/conversion/SBMLLevelVersionConverter.cpp index e3f4e669a9..813131d768 100644 --- a/src/sbml/conversion/SBMLLevelVersionConverter.cpp +++ b/src/sbml/conversion/SBMLLevelVersionConverter.cpp @@ -421,6 +421,7 @@ SBMLLevelVersionConverter::convert() /* undo any changes */ delete currentModel; //!! deletes mDocument->mModel!!!! currentModel = origModel.clone(); + currentModel->setSBMLDocument(mDocument); // tell the model who its parent document is mDocument->mModel = currentModel; // so we have to set it again mDocument->updateSBMLNamespace("core", origLevel, origVersion); @@ -430,30 +431,21 @@ SBMLLevelVersionConverter::convert() { if (resetAnnotations) { - // hack to force the model history to think it haschanged - this will - // change the vacrd if necessary - if (mDocument->isSetModel() && mDocument->getModel()->isSetModelHistory()) - { - ModelHistory * history = mDocument->getModel()->getModelHistory()->clone(); - mDocument->getModel()->setModelHistory(history); - delete history; - } + forceAnnotationReset(mDocument); } + + // need change the unit map as the original will be at old level and version + updateUnitMap(mDocument); } } else { if (resetAnnotations) { - // hack to force the model history to think it haschanged - this will - // change the vcard if necessary - if (mDocument->isSetModel() && mDocument->getModel()->isSetModelHistory()) - { - ModelHistory * history = mDocument->getModel()->getModelHistory()->clone(); - mDocument->getModel()->setModelHistory(history); - delete history; - } + forceAnnotationReset(mDocument); } + // need change the unit map as the original will be at old level and version + updateUnitMap(mDocument); } } } @@ -1321,6 +1313,32 @@ SBMLLevelVersionConverter::collectSpeciesReferenceIds() return srids; } + + +void +SBMLLevelVersionConverter::updateUnitMap(SBMLDocument* d) +{ + if (d && d->isSetModel() && d->getModel()->isPopulatedListFormulaUnitsData()) + { + d->getModel()->removeListFormulaUnitsData(); + d->getModel()->populateListFormulaUnitsData(); + } +} + +void +SBMLLevelVersionConverter::forceAnnotationReset(SBMLDocument* d) +{ + // hack to force the model history to think it haschanged - this will + // change the vacrd if necessary + if (d && d->isSetModel() && d->getModel()->isSetModelHistory()) + { + ModelHistory * history = d->getModel()->getModelHistory()->clone(); + d->getModel()->setModelHistory(history); + delete history; + } +} + + /** @endcond */ @@ -1468,7 +1486,6 @@ SBMLLevelVersionConverter::has_fatal_errors(unsigned int level, unsigned int ver } return false; } - } /** @endcond */ diff --git a/src/sbml/conversion/SBMLLevelVersionConverter.h b/src/sbml/conversion/SBMLLevelVersionConverter.h index 6d16694a1c..bced7839e1 100644 --- a/src/sbml/conversion/SBMLLevelVersionConverter.h +++ b/src/sbml/conversion/SBMLLevelVersionConverter.h @@ -295,6 +295,10 @@ class LIBSBML_EXTERN SBMLLevelVersionConverter : public SBMLConverter // to levels/versions that have no speciesReference ids bool speciesReferenceIdUsed(); + void updateUnitMap(SBMLDocument* d); + + void forceAnnotationReset(SBMLDocument* d); + IdList* collectSpeciesReferenceIds(); void populateMathElements(); diff --git a/src/sbml/conversion/test/TestLevelVersionConverter.cpp b/src/sbml/conversion/test/TestLevelVersionConverter.cpp index 74823e19a0..ee01e2e892 100644 --- a/src/sbml/conversion/test/TestLevelVersionConverter.cpp +++ b/src/sbml/conversion/test/TestLevelVersionConverter.cpp @@ -487,6 +487,44 @@ START_TEST (test_convertToL3V2) END_TEST +START_TEST(test_crash_after_strictconversion_fail) +{ + // replicates https://github.com/sbmlteam/libsbml/issues/333 + + SBMLNamespaces sbmlns(3, 2); + ConversionProperties prop(&sbmlns); + prop.addOption("strict", true, "should validity be preserved"); + prop.addOption("setLevelAndVersion", true, "convert the document to the given level and version"); + prop.addOption("ignorePackages", true); + prop.addOption("addDefaultUnits", false); + + SBMLLevelVersionConverter converter; + converter.setProperties(&prop); + + string filename(TestDataDirectory); + filename += "conversion_seg_fault.xml"; + + SBMLDocument* d = readSBMLFromFile(filename.c_str()); + + // convert to L3V2 + converter.setDocument(d); + int returnCode = converter.convert(); + fail_unless(returnCode == LIBSBML_OPERATION_FAILED); + + Model* m = d->getModel(); + Reaction* r = m->getReaction(0); + KineticLaw* kl = r->getKineticLaw(); + + fail_unless(m != NULL); + fail_unless(m->getSBMLDocument() != NULL); + fail_unless(r->getSBMLDocument() != NULL); + fail_unless(kl->getSBMLDocument() != NULL); + + delete d; +} +END_TEST + + Suite * create_suite_TestLevelVersionConverter (void) { @@ -508,6 +546,7 @@ create_suite_TestLevelVersionConverter (void) tcase_add_test(tcase, test_lv_rxn_variables); tcase_add_test(tcase, test_specref_ref_onlynot); tcase_add_test(tcase, test_specref_ref_real); + tcase_add_test(tcase, test_crash_after_strictconversion_fail); suite_add_tcase(suite, tcase); diff --git a/src/sbml/conversion/test/TestRunner.c b/src/sbml/conversion/test/TestRunner.c index c3c38f74a3..5c6f8ee80f 100644 --- a/src/sbml/conversion/test/TestRunner.c +++ b/src/sbml/conversion/test/TestRunner.c @@ -118,6 +118,7 @@ main (void) int num_failed; setTestDataDirectory(); +// SRunner *runner = srunner_create(create_suite_TestUnitsConverterL2()); SRunner *runner = srunner_create( create_suite_TestConversionOption() ); srunner_add_suite( runner, create_suite_TestSBMLRuleConverter () ); diff --git a/src/sbml/conversion/test/TestUnitsConverterL2.cpp b/src/sbml/conversion/test/TestUnitsConverterL2.cpp index 786860b1f1..14299abfcc 100644 --- a/src/sbml/conversion/test/TestUnitsConverterL2.cpp +++ b/src/sbml/conversion/test/TestUnitsConverterL2.cpp @@ -44,6 +44,7 @@ #include #include +#include #include #include @@ -1301,13 +1302,47 @@ START_TEST (test_convert_time) } END_TEST +START_TEST(test_crash_after_conversion_and_unit_inference) +{ + // replicates https://github.com/sbmlteam/libsbml/issues/334 + + SBMLNamespaces sbmlns(3, 2); + ConversionProperties prop(&sbmlns); + prop.addOption("strict", true, "should validity be preserved"); + prop.addOption("setLevelAndVersion", true, "convert the document to the given level and version"); + prop.addOption("ignorePackages", true); + prop.addOption("addDefaultUnits", false); + + SBMLLevelVersionConverter converter; + converter.setProperties(&prop); + + string filename(TestDataDirectory); + filename += "many-params-function.xml"; + + SBMLDocument* d = readSBMLFromFile(filename.c_str()); + + // convert to L3V2 + converter.setDocument(d); + int returnCode = converter.convert(); + fail_unless(returnCode == LIBSBML_OPERATION_SUCCESS); + + Model* m = d->getModel(); + fail_unless(m->getLevel() == 3); + fail_unless(m->getVersion() == 2); -Suite * -create_suite_TestUnitsConverterL2 (void) -{ - Suite *suite = suite_create("UnitsConverterL2"); - TCase *tcase = tcase_create("UnitsConverterL2"); + m->getListFormulaUnitsData(); + FormulaUnitsData* fud = m->getFormulaUnitsDataForVariable("k3"); + UnitDefinition* ud = fud->getUnitDefinition(); + fail_unless(ud->getLevel() == 3); + fail_unless(ud->getVersion() == 2); +} +END_TEST +Suite * +create_suite_TestUnitsConverterL2(void) +{ + Suite *suite = suite_create("UnitsConverterL2"); + TCase *tcase = tcase_create("UnitsConverterL2"); tcase_add_test(tcase, test_convert_model_volume); tcase_add_test(tcase, test_convert_model_volume1); @@ -1338,6 +1373,8 @@ create_suite_TestUnitsConverterL2 (void) tcase_add_test(tcase, test_convertSpecies_noCompSize5); tcase_add_test(tcase, test_convertParameter_noValue); tcase_add_test(tcase, test_convert_time); + tcase_add_test(tcase, test_crash_after_conversion_and_unit_inference); + suite_add_tcase(suite, tcase); diff --git a/src/sbml/conversion/test/test-data/conversion_seg_fault.xml b/src/sbml/conversion/test/test-data/conversion_seg_fault.xml new file mode 100644 index 0000000000..f994fe62fe --- /dev/null +++ b/src/sbml/conversion/test/test-data/conversion_seg_fault.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + compartment + + + S1 + S2 + + + + + + + + + + + diff --git a/src/sbml/conversion/test/test-data/many-params-function.xml b/src/sbml/conversion/test/test-data/many-params-function.xml new file mode 100644 index 0000000000..527d6c0c93 --- /dev/null +++ b/src/sbml/conversion/test/test-data/many-params-function.xml @@ -0,0 +1,135 @@ + + + + + + + + + InR + + + Ins + + + cellsurface + + + extracellular + + + k1 + + + + k1 + Ins + extracellular + InR + cellsurface + + + + + + + + + Ins_InR + + + cellsurface + + + k3 + + + + + + k3 + Ins_InR + cellsurface + + cellsurface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + function_1 + InR + Ins + cellsurface + extracellular + k1 + + + + + + + + + + + + + + + + + + + cellsurface + + function_3 + Ins_InR + cellsurface + k3 + + + + + + + + diff --git a/src/sbml/packages/comp/util/CompFlatteningConverter.cpp b/src/sbml/packages/comp/util/CompFlatteningConverter.cpp index f5526dc222..dc4a69919e 100644 --- a/src/sbml/packages/comp/util/CompFlatteningConverter.cpp +++ b/src/sbml/packages/comp/util/CompFlatteningConverter.cpp @@ -1266,6 +1266,8 @@ void CompFlatteningConverter::unsetExplicitlyListed() lo->setExplicitlyListed(false); } } + + delete elements; } /** @endcond */ diff --git a/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp b/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp index 24767a865e..a314411a1d 100644 --- a/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp +++ b/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp @@ -415,7 +415,8 @@ START_TEST(test_FbcExtension_create_and_write_L3V1V3) FluxObjective* fluxObjective = objective->createFluxObjective(); fluxObjective->setReaction("J0"); fluxObjective->setCoefficient(1); - fluxObjective->setVariableType("linear"); + fluxObjective->setReaction2("J0"); + fluxObjective->setVariableType("quadratic"); UserDefinedConstraint* userconstraint = mplugin->createUserDefinedConstraint(); userconstraint->setId("uc2"); @@ -423,9 +424,10 @@ START_TEST(test_FbcExtension_create_and_write_L3V1V3) userconstraint->setUpperBound("uc2ub"); UserDefinedConstraintComponent * udcc = userconstraint->createUserDefinedConstraintComponent(); - udcc->setCoefficient(2); + udcc->setCoefficient("ucc1"); udcc->setVariable("Avar"); - udcc->setVariableType("linear"); + udcc->setVariableType("quadratic"); + udcc->setVariable2("Avar2"); // check annotations on several types FbcSBasePlugin* sbaseplugin = dynamic_cast(compartment->getPlugin("fbc")); diff --git a/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml b/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml index 583b6a52e7..6e696a7167 100644 --- a/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml +++ b/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml @@ -32,14 +32,14 @@ - + - + diff --git a/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml b/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml index b7090bb8d0..b73b4e1db1 100644 --- a/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml +++ b/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml @@ -21,14 +21,14 @@ - + - + diff --git a/src/sbml/packages/fbc/sbml/FluxObjective.cpp b/src/sbml/packages/fbc/sbml/FluxObjective.cpp index a51a16b533..419f8f8449 100644 --- a/src/sbml/packages/fbc/sbml/FluxObjective.cpp +++ b/src/sbml/packages/fbc/sbml/FluxObjective.cpp @@ -69,6 +69,7 @@ FluxObjective::FluxObjective (unsigned int level, unsigned int version, unsigned , mCoefficient (numeric_limits::quiet_NaN()) , mIsSetCoefficient (false) , mVariableType (FBC_VARIABLE_TYPE_INVALID) + , mReaction2 ("") { // set an SBMLNamespaces derived object of this package setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion)); @@ -86,6 +87,7 @@ FluxObjective::FluxObjective (FbcPkgNamespaces* fbcns) , mCoefficient (numeric_limits::quiet_NaN()) , mIsSetCoefficient (false) , mVariableType (FBC_VARIABLE_TYPE_INVALID) + , mReaction2 ("") { // set the element namespace of this object setElementNamespace(fbcns->getURI()); @@ -104,6 +106,7 @@ FluxObjective::FluxObjective(const FluxObjective& orig) , mCoefficient ( orig.mCoefficient ) , mIsSetCoefficient ( orig.mIsSetCoefficient ) , mVariableType ( orig.mVariableType ) + , mReaction2 (orig.mReaction2) { } @@ -123,6 +126,7 @@ FluxObjective::operator=(const FluxObjective& rhs) mCoefficient = rhs.mCoefficient; mIsSetCoefficient = rhs.mIsSetCoefficient; mVariableType = rhs.mVariableType; + mReaction2 = rhs.mReaction2; } return *this; } @@ -176,6 +180,16 @@ FluxObjective::getReaction() const } +/* + * Returns the value of the "reaction2" attribute of this FluxObjective. + */ +const std::string& +FluxObjective::getReaction2() const +{ + return mReaction2; +} + + /* * Returns the value of the "coefficient" attribute of this FluxObjective. */ @@ -238,6 +252,16 @@ FluxObjective::isSetReaction() const } +/* + * Predicate returning @c true if this FluxObjective's "reaction2" attribute is + * set. + */ +bool +FluxObjective::isSetReaction2() const +{ + return (mReaction2.empty() == false); +} + /* * Predicate returning @c true if this FluxObjective's "coefficient" attribute * is set. @@ -287,7 +311,17 @@ FluxObjective::setName(const std::string& name) int FluxObjective::setReaction(const std::string& reaction) { - return SyntaxChecker::checkAndSetSId(reaction ,mReaction); + return SyntaxChecker::checkAndSetSId(reaction, mReaction); +} + + +/* + * Sets reaction2 and returns value indicating success. + */ +int +FluxObjective::setReaction2(const std::string& reaction) +{ + return SyntaxChecker::checkAndSetSId(reaction, mReaction2); } @@ -418,6 +452,25 @@ FluxObjective::unsetReaction() } +/* + * Unsets reaction and returns value indicating success. + */ +int +FluxObjective::unsetReaction2() +{ + mReaction2.erase(); + + if (mReaction2.empty() == true) + { + return LIBSBML_OPERATION_SUCCESS; + } + else + { + return LIBSBML_OPERATION_FAILED; + } +} + + /* * Unsets coefficient and returns value indicating success. */ @@ -460,6 +513,10 @@ FluxObjective::renameSIdRefs(const std::string& oldid, const std::string& newid) { setReaction(newid); } + if (isSetReaction2() == true && mReaction2 == oldid) + { + setReaction2(newid); + } } @@ -697,7 +754,12 @@ FluxObjective::getAttribute(const std::string& attributeName, value = getVariableTypeAsString(); return_value = LIBSBML_OPERATION_SUCCESS; } - + else if (attributeName == "reaction2") + { + value = getReaction2(); + return_value = LIBSBML_OPERATION_SUCCESS; + } + return return_value; } @@ -736,6 +798,10 @@ FluxObjective::isSetAttribute(const std::string& attributeName) const { value = isSetVariableType(); } + else if (attributeName == "reaction2") + { + value = isSetReaction2(); + } return value; } @@ -845,6 +911,10 @@ FluxObjective::setAttribute(const std::string& attributeName, { return_value = setVariableType(value); } + else if (attributeName == "reaction2") + { + return_value = setReaction2(value); + } return return_value; } @@ -883,6 +953,10 @@ FluxObjective::unsetAttribute(const std::string& attributeName) { value = unsetVariableType(); } + else if (attributeName == "reaction2") + { + value = unsetReaction2(); + } return value; } @@ -912,6 +986,7 @@ FluxObjective::addExpectedAttributes(ExpectedAttributes& attributes) if (level == 3 && coreVersion == 1 && pkgVersion == 3) { attributes.add("variableType"); + attributes.add("reaction2"); } } @@ -1052,6 +1127,17 @@ FluxObjective::readAttributes (const XMLAttributes& attributes, } + assigned = attributes.readInto("reaction2", mReaction2); + if (assigned && !SyntaxChecker::isValidSBMLSId(mReaction2)) + { + // + // Logs an error if the "id" attribute doesn't + // conform to the SBML type SId. + // + log->logPackageError("fbc", FbcFluxObjectReactionMustBeSIdRef, + getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn()); + } + unsigned int numErrs = log->getNumErrors(); mIsSetCoefficient = attributes.readInto("coefficient", mCoefficient, log); @@ -1153,6 +1239,9 @@ FluxObjective::writeAttributes (XMLOutputStream& stream) const FbcVariableType_toString(mVariableType)); } + if (isSetReaction2() == true) + stream.writeAttribute("reaction2", getPrefix(), mReaction2); + // // (EXTENSION) // @@ -1542,6 +1631,13 @@ FluxObjective_getVariableTypeAsString(const FluxObjective_t * fo) return (char*)(FbcVariableType_toString(fo->getVariableType())); } +LIBSBML_EXTERN +const char * +FluxObjective_getReaction2(const FluxObjective_t * fo) +{ + return (fo != NULL && fo->isSetReaction2()) ? fo->getReaction2().c_str() : NULL; +} + LIBSBML_EXTERN int @@ -1583,6 +1679,14 @@ FluxObjective_isSetVariableType(const FluxObjective_t * fo) } +LIBSBML_EXTERN +int +FluxObjective_isSetReaction2(const FluxObjective_t * fo) +{ + return (fo != NULL) ? static_cast(fo->isSetReaction2()) : 0; +} + + /* * Sets the value of the "id" attribute of this FluxObjective_t. */ @@ -1652,6 +1756,18 @@ FluxObjective_setVariableTypeAsString(FluxObjective_t * fo, LIBSBML_INVALID_OBJECT; } + +LIBSBML_EXTERN +int +FluxObjective_setReaction2(FluxObjective_t * fo, const char * reaction) +{ + if (fo != NULL) + return (reaction == NULL) ? fo->setReaction2("") : fo->setReaction2(reaction); + else + return LIBSBML_INVALID_OBJECT; +} + + LIBSBML_EXTERN int FluxObjective_unsetId(FluxObjective_t * fo) @@ -1695,6 +1811,14 @@ FluxObjective_unsetVariableType(FluxObjective_t * fo) } +LIBSBML_EXTERN +int +FluxObjective_unsetReaction2(FluxObjective_t * fo) +{ + return (fo != NULL) ? fo->unsetReaction2() : LIBSBML_INVALID_OBJECT; +} + + LIBSBML_EXTERN int FluxObjective_hasRequiredAttributes(const FluxObjective_t * fo) diff --git a/src/sbml/packages/fbc/sbml/FluxObjective.h b/src/sbml/packages/fbc/sbml/FluxObjective.h index 47796ac403..ca3f98b953 100644 --- a/src/sbml/packages/fbc/sbml/FluxObjective.h +++ b/src/sbml/packages/fbc/sbml/FluxObjective.h @@ -113,6 +113,7 @@ class LIBSBML_EXTERN FluxObjective : public SBase double mCoefficient; bool mIsSetCoefficient; FbcVariableType_t mVariableType; + std::string mReaction2; /** @endcond */ public: @@ -215,6 +216,14 @@ class LIBSBML_EXTERN FluxObjective : public SBase */ virtual const std::string& getReaction() const; + /** + * Returns the value of the "reaction2" attribute of this FluxObjective. + * + * @return the value of the "reaction2" attribute of this FluxObjective as a + * string. + */ + virtual const std::string& getReaction2() const; + /** * Returns the value of the "coefficient" attribute of this FluxObjective. @@ -284,6 +293,15 @@ class LIBSBML_EXTERN FluxObjective : public SBase */ virtual bool isSetReaction() const; + /** + * Predicate returning @c true if this FluxObjective's "reaction2" attribute + * is set. + * + * @return @c true if this FluxObjective's "reaction2" attribute has been set, + * otherwise @c false is returned. + */ + virtual bool isSetReaction2() const; + /** * Predicate returning @c true if this FluxObjective's "coefficient" @@ -334,6 +352,16 @@ class LIBSBML_EXTERN FluxObjective : public SBase */ virtual int setReaction(const std::string& reaction); + /** + * Sets the value of the "reaction2" attribute of this FluxObjective. + * + * @param reaction the value of the "reaction2" attribute to be set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} + */ + virtual int setReaction2(const std::string& reaction); /** * Sets the value of the "coefficient" attribute of this FluxObjective. @@ -405,6 +433,16 @@ class LIBSBML_EXTERN FluxObjective : public SBase virtual int unsetReaction(); + /** + * Unsets the value of the "reaction2" attribute of this FluxObjective. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + */ + virtual int unsetReaction2(); + + /** * Unsets the value of the "coefficient" attribute of this FluxObjective. * @@ -1201,6 +1239,21 @@ char * FluxObjective_getVariableTypeAsString(const FluxObjective_t * fo); +/** + * Returns the value of the "reaction2" attribute of the given FluxObjective_t + * structure. + * + * @param fo the FluxObjective_t structure. + * + * @return the reaction of this structure. + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +const char * +FluxObjective_getReaction2(const FluxObjective_t * fo); + + /** * Predicate returning @c 1 (true) if this FluxObjective_t's "id" attribute is * set. @@ -1283,6 +1336,22 @@ int FluxObjective_isSetVariableType(const FluxObjective_t * fo); +/** + * Predicate returning @c 1 (true) if the given FluxObjective_t structure's "reaction2" + * is set. + * + * @param fo the FluxObjective_t structure. + * + * @return @c 1 (true) if the "reaction2" of this FluxObjective_t structure is + * set, @c 0 (false) otherwise. + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +int +FluxObjective_isSetReaction2(const FluxObjective_t * fo); + + /** * Sets the value of the "id" attribute of this FluxObjective_t. * @@ -1423,6 +1492,32 @@ FluxObjective_setVariableTypeAsString(FluxObjective_t * fo, const char * variableType); +/** + * Sets the "reaction2" attribute of the given FluxObjective_t structure. + * + * This function copies the string given in @p reaction. If the string is + * a null pointer, this function is equivalent to calling FluxObjective_unsetReaction(). + * + * @param fo the FluxObjective_t structure. + * + * @param reaction the string to which the structures "reaction2" attribute should be + * set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @note Using this function with a null pointer for @p reaction is equivalent to + * unsetting the value of the "reaction2" attribute. + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +int +FluxObjective_setReaction2(FluxObjective_t * fo, const char * reaction); + + /** * Unsets the value of the "id" attribute of this FluxObjective_t. * @@ -1512,6 +1607,24 @@ int FluxObjective_unsetVariableType(FluxObjective_t * fo); +/** + * Unsets the value of the "reaction2" attribute of the given + * FluxObjective_t structure. + * + * @param fo the FluxObjective_t structure. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +int +FluxObjective_unsetReaction2(FluxObjective_t * fo); + + /** * Predicate returning @c 1 (true) or @c 0 (false) depending on whether all the required * attributes of the given FluxObjective_t structure have been set. diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp index ffb3880e80..d62ed00d53 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp @@ -63,9 +63,9 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent( unsigned int pkgVersion) : SBase(level, version) - , mCoefficient (util_NaN()) - , mIsSetCoefficient (false) + , mCoefficient ("") , mVariable ("") + , mVariable2 ("") , mVariableType (FBC_VARIABLE_TYPE_INVALID) { setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion)); @@ -79,9 +79,9 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent( UserDefinedConstraintComponent::UserDefinedConstraintComponent(FbcPkgNamespaces *fbcns) : SBase(fbcns) - , mCoefficient (util_NaN()) - , mIsSetCoefficient (false) + , mCoefficient ("") , mVariable ("") + , mVariable2 ("") , mVariableType (FBC_VARIABLE_TYPE_INVALID) { setElementNamespace(fbcns->getURI()); @@ -96,8 +96,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(const UserDefinedConstraintComponent& orig) : SBase( orig ) , mCoefficient ( orig.mCoefficient ) - , mIsSetCoefficient ( orig.mIsSetCoefficient ) , mVariable ( orig.mVariable ) + , mVariable2 ( orig.mVariable2 ) , mVariableType ( orig.mVariableType ) { } @@ -114,8 +114,8 @@ UserDefinedConstraintComponent::operator=(const UserDefinedConstraintComponent& { SBase::operator=(rhs); mCoefficient = rhs.mCoefficient; - mIsSetCoefficient = rhs.mIsSetCoefficient; mVariable = rhs.mVariable; + mVariable2 = rhs.mVariable2; mVariableType = rhs.mVariableType; } @@ -168,7 +168,7 @@ UserDefinedConstraintComponent::getName() const * Returns the value of the "coefficient" attribute of this * UserDefinedConstraintComponent. */ -double +const std::string& UserDefinedConstraintComponent::getCoefficient() const { return mCoefficient; @@ -186,6 +186,17 @@ UserDefinedConstraintComponent::getVariable() const } +/* + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + */ +const std::string& +UserDefinedConstraintComponent::getVariable2() const +{ + return mVariable2; +} + + /* * Returns the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -238,7 +249,7 @@ UserDefinedConstraintComponent::isSetName() const bool UserDefinedConstraintComponent::isSetCoefficient() const { - return mIsSetCoefficient; + return (mCoefficient.empty() == false); } @@ -253,6 +264,17 @@ UserDefinedConstraintComponent::isSetVariable() const } +/* + * Predicate returning @c true if this UserDefinedConstraintComponent's + * "variable2" attribute is set. + */ +bool +UserDefinedConstraintComponent::isSetVariable2() const +{ + return (mVariable2.empty() == false); +} + + /* * Predicate returning @c true if this UserDefinedConstraintComponent's * "variableType" attribute is set. @@ -313,7 +335,7 @@ UserDefinedConstraintComponent::setName(const std::string& name) * UserDefinedConstraintComponent. */ int -UserDefinedConstraintComponent::setCoefficient(double coefficient) +UserDefinedConstraintComponent::setCoefficient(const std::string& coefficient) { unsigned int coreLevel = getLevel(); unsigned int coreVersion = getVersion(); @@ -321,14 +343,18 @@ UserDefinedConstraintComponent::setCoefficient(double coefficient) if (coreLevel == 3 && coreVersion == 1 && pkgVersion == 3) { - mCoefficient = coefficient; - mIsSetCoefficient = true; - return LIBSBML_OPERATION_SUCCESS; + if (!(SyntaxChecker::isValidInternalSId(coefficient))) + { + return LIBSBML_INVALID_ATTRIBUTE_VALUE; + } + else + { + mCoefficient = coefficient; + return LIBSBML_OPERATION_SUCCESS; + } } else { - mCoefficient = coefficient; - mIsSetCoefficient = false; return LIBSBML_UNEXPECTED_ATTRIBUTE; } } @@ -364,6 +390,36 @@ UserDefinedConstraintComponent::setVariable(const std::string& variable) } +/* + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + */ +int +UserDefinedConstraintComponent::setVariable2(const std::string& variable) +{ + unsigned int coreLevel = getLevel(); + unsigned int coreVersion = getVersion(); + unsigned int pkgVersion = getPackageVersion(); + + if (coreLevel == 3 && coreVersion == 1 && pkgVersion == 3) + { + if (!(SyntaxChecker::isValidInternalSId(variable))) + { + return LIBSBML_INVALID_ATTRIBUTE_VALUE; + } + else + { + mVariable2 = variable; + return LIBSBML_OPERATION_SUCCESS; + } + } + else + { + return LIBSBML_UNEXPECTED_ATTRIBUTE; + } +} + + /* * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -473,10 +529,9 @@ UserDefinedConstraintComponent::unsetName() int UserDefinedConstraintComponent::unsetCoefficient() { - mCoefficient = util_NaN(); - mIsSetCoefficient = false; + mCoefficient.erase(); - if (isSetCoefficient() == false) + if (mCoefficient.empty() == true) { return LIBSBML_OPERATION_SUCCESS; } @@ -507,6 +562,26 @@ UserDefinedConstraintComponent::unsetVariable() } +/* + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + */ +int +UserDefinedConstraintComponent::unsetVariable2() +{ + mVariable2.erase(); + + if (mVariable2.empty() == true) + { + return LIBSBML_OPERATION_SUCCESS; + } + else + { + return LIBSBML_OPERATION_FAILED; + } +} + + /* * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -526,10 +601,20 @@ void UserDefinedConstraintComponent::renameSIdRefs(const std::string& oldid, const std::string& newid) { + if (isSetCoefficient() && mCoefficient == oldid) + { + setCoefficient(newid); + } + if (isSetVariable() && mVariable == oldid) { setVariable(newid); } + + if (isSetVariable2() && mVariable2 == oldid) + { + setVariable2(newid); + } } @@ -714,17 +799,6 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName, { int return_value = SBase::getAttribute(attributeName, value); - if (return_value == LIBSBML_OPERATION_SUCCESS) - { - return return_value; - } - - if (attributeName == "coefficient") - { - value = getCoefficient(); - return_value = LIBSBML_OPERATION_SUCCESS; - } - return return_value; } @@ -778,11 +852,21 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName, value = getName(); return_value = LIBSBML_OPERATION_SUCCESS; } + else if (attributeName == "coefficient") + { + value = getCoefficient(); + return_value = LIBSBML_OPERATION_SUCCESS; + } else if (attributeName == "variable") { value = getVariable(); return_value = LIBSBML_OPERATION_SUCCESS; } + else if (attributeName == "variable2") + { + value = getVariable2(); + return_value = LIBSBML_OPERATION_SUCCESS; + } else if (attributeName == "variableType") { value = getVariableTypeAsString(); @@ -824,6 +908,10 @@ UserDefinedConstraintComponent::isSetAttribute(const std::string& { value = isSetVariable(); } + else if (attributeName == "variable2") + { + value = isSetVariable2(); + } else if (attributeName == "variableType") { value = isSetVariableType(); @@ -886,11 +974,6 @@ UserDefinedConstraintComponent::setAttribute(const std::string& attributeName, { int return_value = SBase::setAttribute(attributeName, value); - if (attributeName == "coefficient") - { - return_value = setCoefficient(value); - } - return return_value; } @@ -937,10 +1020,18 @@ UserDefinedConstraintComponent::setAttribute(const std::string& attributeName, { return_value = setName(value); } + else if (attributeName == "coefficient") + { + return_value = setCoefficient(value); + } else if (attributeName == "variable") { return_value = setVariable(value); } + else if (attributeName == "variable2") + { + return_value = setVariable2(value); + } else if (attributeName == "variableType") { return_value = setVariableType(value); @@ -981,6 +1072,10 @@ UserDefinedConstraintComponent::unsetAttribute(const std::string& { value = unsetVariable(); } + else if (attributeName == "variable2") + { + value = unsetVariable2(); + } else if (attributeName == "variableType") { value = unsetVariableType(); @@ -1014,6 +1109,7 @@ UserDefinedConstraintComponent::addExpectedAttributes(ExpectedAttributes& attributes.add("name"); attributes.add("coefficient"); attributes.add("variable"); + attributes.add("variable2"); attributes.add("variableType"); } } @@ -1162,25 +1258,29 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& } // - // coefficient double (use = "required" ) + // coefficient SIdRef (use = "required" ) // numErrs = log ? log->getNumErrors() : 0; - mIsSetCoefficient = attributes.readInto("coefficient", mCoefficient); + XMLTriple tripleCOEFF("coefficient", mURI, getPrefix()); + assigned = attributes.readInto("coefficient", mCoefficient); - if ( mIsSetCoefficient == false && log) + if (assigned == true) { - if (log && log->getNumErrors() == numErrs + 1 && - log->contains(XMLAttributeTypeMismatch)) + if (mCoefficient.empty() == true) { - log->remove(XMLAttributeTypeMismatch); - std::string message = "Fbc attribute 'coefficient' from the " - " element must be a double."; - log->logPackageError("fbc", - FbcUserDefinedConstraintComponentCoefficientMustBeDouble, pkgVersion, - level, version, message, getLine(), getColumn()); + logEmptyString("coefficient", level, version, ""); } - else + else if (SyntaxChecker::isValidSBMLSId(mCoefficient) == false) + { + log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, + "The coefficient on the <" + getElementName() + "> is '" + mCoefficient + "', which does " + "not conform to the syntax.", getLine(), getColumn()); + } + } + else + { + if (log) { std::string message = "Fbc attribute 'coefficient' is missing from the " " element."; @@ -1229,6 +1329,34 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& } } + // + // variable2 SIdRef (use = "optional" ) + // + + assigned = attributes.readInto("variable2", mVariable2); + + if (assigned == true) + { + if (mVariable2.empty() == true) + { + logEmptyString(mVariable2, level, version, + ""); + } + else if (SyntaxChecker::isValidSBMLSId(mVariable2) == false) + { + std::string msg = "The variable2 attribute on the <" + getElementName() + + ">"; + if (isSetId()) + { + msg += " with id '" + getId() + "'"; + } + + msg += " is '" + mVariable2 + "', which does not conform to the syntax."; + log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, msg, + getLine(), getColumn()); + } + } + // // variableType enum (use = "required" ) // @@ -1274,6 +1402,35 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& version, message, getLine(), getColumn()); } } + + // + // variable2 SIdRef (use = "optional" ) + // + + assigned = attributes.readInto("variable2", mVariable2); + + if (assigned == true) + { + if (mVariable2.empty() == true) + { + logEmptyString(mVariable2, level, version, + ""); + } + else if (SyntaxChecker::isValidSBMLSId(mVariable2) == false) + { + std::string msg = "The variable2 attribute on the <" + getElementName() + + ">"; + if (isSetId()) + { + msg += " with id '" + getId() + "'"; + } + + msg += " is '" + mVariable2 + "', which does not conform to the syntax."; + log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, msg, + getLine(), getColumn()); + } + } + } /** @endcond */ @@ -1335,6 +1492,11 @@ UserDefinedConstraintComponent::writeL3V1V3Attributes(XMLOutputStream& stream) stream.writeAttribute("variable", getPrefix(), mVariable); } + if (isSetVariable2() == true) + { + stream.writeAttribute("variable2", getPrefix(), mVariable2); + } + if (isSetVariableType() == true) { stream.writeAttribute("variableType", getPrefix(), @@ -1439,11 +1601,16 @@ UserDefinedConstraintComponent_getName(const UserDefinedConstraintComponent_t * * UserDefinedConstraintComponent_t. */ LIBSBML_EXTERN -double +char* UserDefinedConstraintComponent_getCoefficient(const UserDefinedConstraintComponent_t * udcc) { - return (udcc != NULL) ? udcc->getCoefficient() : util_NaN(); + if (udcc == NULL) + { + return NULL; + } + + return udcc->getName().empty() ? NULL : safe_strdup(udcc->getCoefficient().c_str()); } @@ -1465,6 +1632,24 @@ UserDefinedConstraintComponent_getVariable(const safe_strdup(udcc->getVariable().c_str()); } +/* + * Returns the value of the "variable" attribute of this + * UserDefinedConstraintComponent_t. + */ +LIBSBML_EXTERN +char * +UserDefinedConstraintComponent_getVariable2(const + UserDefinedConstraintComponent_t * udcc) +{ + if (udcc == NULL) + { + return NULL; + } + + return udcc->getVariable2().empty() ? NULL : + safe_strdup(udcc->getVariable2().c_str()); +} + /* * Returns the value of the "variableType" attribute of this @@ -1549,6 +1734,19 @@ UserDefinedConstraintComponent_isSetVariable(const } +/* + * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's + * "variable2" attribute is set. + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_isSetVariable2(const + UserDefinedConstraintComponent_t * udcc) +{ + return (udcc != NULL) ? static_cast(udcc->isSetVariable2()) : 0; +} + + /* * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "variableType" attribute is set. @@ -1597,7 +1795,7 @@ int UserDefinedConstraintComponent_setCoefficient( UserDefinedConstraintComponent_t * udcc, - double coefficient) + const char * coefficient) { return (udcc != NULL) ? udcc->setCoefficient(coefficient) : LIBSBML_INVALID_OBJECT; @@ -1619,6 +1817,21 @@ UserDefinedConstraintComponent_setVariable( } +/* + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_setVariable2( + UserDefinedConstraintComponent_t * + udcc, + const char * variable) +{ + return (udcc != NULL) ? udcc->setVariable2(variable) : LIBSBML_INVALID_OBJECT; +} + + /* * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. @@ -1703,6 +1916,19 @@ UserDefinedConstraintComponent_unsetVariable(UserDefinedConstraintComponent_t * } +/* + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t + * udcc) +{ + return (udcc != NULL) ? udcc->unsetVariable2() : LIBSBML_INVALID_OBJECT; +} + + /* * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h index ca7a41d5ce..59def6fb59 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h @@ -93,9 +93,9 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase /** @cond doxygenLibsbmlInternal */ - double mCoefficient; - bool mIsSetCoefficient; + std::string mCoefficient; std::string mVariable; + std::string mVariable2; FbcVariableType_t mVariableType; /** @endcond */ @@ -196,9 +196,9 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase * UserDefinedConstraintComponent. * * @return the value of the "coefficient" attribute of this - * UserDefinedConstraintComponent as a double. + * UserDefinedConstraintComponent as a string. */ - double getCoefficient() const; + const std::string& getCoefficient() const; /** @@ -211,6 +211,16 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase const std::string& getVariable() const; + /** + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + * + * @return the value of the "variable2" attribute of this + * UserDefinedConstraintComponent as a string. + */ + const std::string& getVariable2() const; + + /** * Returns the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -285,6 +295,16 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase bool isSetVariable() const; + /** + * Predicate returning @c true if this UserDefinedConstraintComponent's + * "variable2" attribute is set. + * + * @return @c true if this UserDefinedConstraintComponent's "variable2" + * attribute has been set, otherwise @c false is returned. + */ + bool isSetVariable2() const; + + /** * Predicate returning @c true if this UserDefinedConstraintComponent's * "variableType" attribute is set. @@ -333,14 +353,16 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase * Sets the value of the "coefficient" attribute of this * UserDefinedConstraintComponent. * - * @param coefficient double value of the "coefficient" attribute to be set. + * @param coefficient std::string& value of the "coefficient" attribute to be + * set. * - * @copydetails doc_returns_success_code + * @copydetails doc_returns_one_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} - * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, - * OperationReturnValues_t} + * + * Calling this function with @p coefficient = @c NULL or an empty string is + * equivalent to calling unsetCoefficient(). */ - int setCoefficient(double coefficient); + int setCoefficient(const std::string& coefficient); /** @@ -357,6 +379,20 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase int setVariable(const std::string& variable); + /** + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + * + * @param variable std::string& value of the "variable2" attribute to be set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, + * OperationReturnValues_t} + */ + int setVariable2(const std::string& variable); + + /** * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -435,6 +471,16 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase int unsetVariable(); + /** + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + */ + int unsetVariable2(); + /** * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -988,12 +1034,14 @@ UserDefinedConstraintComponent_getName(const UserDefinedConstraintComponent_t * * is sought. * * @return the value of the "coefficient" attribute of this - * UserDefinedConstraintComponent_t as a double. + * UserDefinedConstraintComponent_t as a pointer to a string. + * + * @copydetails doc_returned_owned_char * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN -double +char * UserDefinedConstraintComponent_getCoefficient(const UserDefinedConstraintComponent_t * udcc); @@ -1018,6 +1066,26 @@ UserDefinedConstraintComponent_getVariable(const UserDefinedConstraintComponent_t * udcc); +/** + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure whose variable2 + * is sought. + * + * @return the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t as a pointer to a string. + * + * @copydetails doc_returned_owned_char + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +char * +UserDefinedConstraintComponent_getVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Returns the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. @@ -1070,6 +1138,26 @@ UserDefinedConstraintComponent_getVariableTypeAsString(const UserDefinedConstraintComponent_t * udcc); +/** + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure whose variable is + * sought. + * + * @return the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t as a pointer to a string. + * + * @copydetails doc_returned_owned_char + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +char * +UserDefinedConstraintComponent_getVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "id" attribute is set. @@ -1138,6 +1226,23 @@ UserDefinedConstraintComponent_isSetVariable(const UserDefinedConstraintComponent_t * udcc); +/** + * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's + * "variable2" attribute is set. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @return @c 1 (true) if this UserDefinedConstraintComponent_t's "variable2" + * attribute has been set, otherwise @c 0 (false) is returned. + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_isSetVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "variableType" attribute is set. @@ -1157,6 +1262,23 @@ UserDefinedConstraintComponent_isSetVariableType(const UserDefinedConstraintComponent_t * udcc); +/** + * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's + * "variable2" attribute is set. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @return @c 1 (true) if this UserDefinedConstraintComponent_t's "variable2" + * attribute has been set, otherwise @c 0 (false) is returned. + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_isSetVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Sets the value of the "id" attribute of this * UserDefinedConstraintComponent_t. @@ -1210,13 +1332,17 @@ UserDefinedConstraintComponent_setName(UserDefinedConstraintComponent_t * udcc, * * @param udcc the UserDefinedConstraintComponent_t structure. * - * @param coefficient double value of the "coefficient" attribute to be set. + * @param coefficient const char * value of the "coefficient" attribute to be + * set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} * + * Calling this function with @p coefficient = @c NULL or an empty string is + * equivalent to calling UserDefinedConstraintComponent_unsetCoefficient(). + * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN @@ -1224,7 +1350,7 @@ int UserDefinedConstraintComponent_setCoefficient( UserDefinedConstraintComponent_t * udcc, - double coefficient); + const char * coefficient); /** @@ -1250,6 +1376,29 @@ UserDefinedConstraintComponent_setVariable( const char * variable); +/** + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @param variable2 const char * value of the "variable2" attribute to be set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_setVariable2( + UserDefinedConstraintComponent_t * + udcc, + const char * variable2); + + /** * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. @@ -1378,6 +1527,25 @@ UserDefinedConstraintComponent_unsetVariable(UserDefinedConstraintComponent_t * udcc); +/** + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t + * udcc); + + /** * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. diff --git a/src/sbml/packages/fbc/validator/FbcSBMLError.h b/src/sbml/packages/fbc/validator/FbcSBMLError.h index 66ed79d638..1a24baa36e 100644 --- a/src/sbml/packages/fbc/validator/FbcSBMLError.h +++ b/src/sbml/packages/fbc/validator/FbcSBMLError.h @@ -115,6 +115,8 @@ typedef enum , FbcFluxObjectCoefficientMustBeDouble = 2020607 /*!< The attribute 'fbc:coefficient' must be of the data type double */ , FbcFluxObjectCoefficientWhenStrict = 2020608 /*!< The 'fbc:coefficient' must be declared when strict */ , FbcFluxObjectiveVariableTypeMustBeFbcVariableTypeEnum = 2020609 +, FbcFluxObjectReaction2MustBeSIdRef = 2020610 /*!< Datatype for 'fbc:reaction' must be SIdRef */ +, FbcFluxObjectReaction2MustExist = 2020611 /*!< 'fbc:reaction' must refer to valid reaction */ , FbcReactionOnlyOneGeneProdAss = 2020701 /*!< One GeneProductAssociation in a Reaction */ , FbcReactionAllowedAttributes = 2020702 /*!< Fbc attributes on a Reaction */ @@ -165,11 +167,11 @@ typedef enum , FbcUserDefinedConstraintComponentAllowedCoreAttributes = 2021301 , FbcUserDefinedConstraintComponentAllowedCoreElements = 2021302 , FbcUserDefinedConstraintComponentAllowedAttributes = 2021303 -, FbcUserDefinedConstraintComponentCoefficientMustBeDouble = 2021304 +, FbcUserDefinedConstraintComponentCoefficientMustBeParameter = 2021304 , FbcUserDefinedConstraintComponentVariableMustBeReactionOrParameter= 2021305 , FbcUserDefinedConstraintComponentVariableTypeMustBeFbcVariableTypeEnum= 2021306 , FbcUserDefinedConstraintComponentNameMustBeString = 2021307 - +, FbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter= 2021308 , FbcUserDefinedConstraintAllowedCoreAttributes = 2021401 , FbcUserDefinedConstraintAllowedCoreElements = 2021402 , FbcUserDefinedConstraintAllowedAttributes = 2021403 diff --git a/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h b/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h index cc90278465..e88404f4e1 100644 --- a/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h +++ b/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h @@ -903,6 +903,37 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = } }, + // 2020610 + { FbcFluxObjectReaction2MustBeSIdRef, + "Datatype for 'fbc:reaction2' must be SIdRef", + LIBSBML_CAT_GENERAL_CONSISTENCY, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_ERROR, + "The value of the attribute 'fbc:reaction2' of a object " + "must conform to the syntax of the SBML data type 'SIdRef'.", + { "", + "", + "L3V1 Fbc V3, Section 3.7" + } + }, + + // 2020611 + { FbcFluxObjectReaction2MustExist, + "'fbc:reaction2' must refer to valid reaction", + LIBSBML_CAT_GENERAL_CONSISTENCY, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_ERROR, + "The value of the attribute 'fbc:reaction2' of a " + " object must be the identifier of an existing " + "object defined in the enclosing object.", + { "", + "", + "L3V1 Fbc V3, Section 3.7" + } + }, + // 2020701 @@ -1616,9 +1647,10 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = LIBSBML_SEV_ERROR, "An object must have the required " "attributes 'fbc:coefficient', 'fbc:variable' and 'fbc:variableType', and " - "may have the optional attributes 'fbc:id' and 'fbc:name'. No other " - "attributes from the SBML Level 3 Flux Balance Constraints namespaces are " - "permitted on an object. ", + "may have the optional attributes 'fbc:id', 'fbc:name' and " + "'fbc:variable2'. No other attributes from the SBML Level 3 Flux Balance " + "Constraints namespaces are permitted on an " + " object. ", { "", "", "" @@ -1626,14 +1658,15 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = }, // 2021304 - { FbcUserDefinedConstraintComponentCoefficientMustBeDouble, - "The 'coefficient' attribute must be Double.", + { FbcUserDefinedConstraintComponentCoefficientMustBeParameter, + "The attribute 'coefficient' must point to Parameter object.", LIBSBML_CAT_GENERAL_CONSISTENCY, LIBSBML_SEV_NOT_APPLICABLE, LIBSBML_SEV_NOT_APPLICABLE, LIBSBML_SEV_ERROR, - "The attribute 'fbc:coefficient' on an " - "must have a value of data type 'double'.", + "The value of the attribute 'fbc:coefficient' of an " + " object must be the identifier of an " + "existing object defined in the enclosing object.", { "", "", "" @@ -1690,6 +1723,23 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = } }, + // 2021308 + { FbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter, + "The attribute 'variable2' must point to ReactionOrParameter object.", + LIBSBML_CAT_GENERAL_CONSISTENCY, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_ERROR, + "The value of the attribute 'fbc:variable2' of an " + " object must be the identifier of an " + "existing or object defined in the enclosing " + "object.", + { "", + "", + "" + } + }, + // 2021401 { FbcUserDefinedConstraintAllowedCoreAttributes, "Core attributes allowed on .", diff --git a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp index 0fdb30d569..fb7946adf9 100644 --- a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp +++ b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp @@ -162,8 +162,8 @@ END_CONSTRAINT // 20601 - caught at read // 20602 - caught at read // 20603 - caught at read -// 20606 - caught at read -// 20606 - caught at read +// 20604 - caught at read +// 20605 - caught at read // 20606 START_CONSTRAINT (FbcFluxObjectReactionMustExist, FluxObjective, fo) @@ -217,6 +217,36 @@ START_CONSTRAINT(FbcFluxObjectCoefficientWhenStrict, FluxObjective, fo) } END_CONSTRAINT +// 20809 - caught at read +// 20810 - caught at read + +// 20811 +START_CONSTRAINT(FbcFluxObjectReaction2MustExist, FluxObjective, fo) +{ + pre(fo.isSetReaction2()); + + bool fail = false; + + msg = "The "; + if (fo.isSetId()) { + msg += "with the id '" + fo.getId() + "' "; + } + msg += "refers to a reaction with id '"; + msg += fo.getReaction2(); + msg += "' that does not exist within the ."; + + std::string reaction = fo.getReaction2(); + + if (m.getReaction(reaction) == NULL) + { + fail = true; + } + + inv(fail == false); +} +END_CONSTRAINT + + // 20701 - caught at read // 20702 - caught at read // 20703 - caught at read @@ -826,7 +856,31 @@ END_CONSTRAINT // 21301 - caught at read // 21302 - caught at read // 21303 - caught at read -// 21304 - caught at read + +// 21304 +START_CONSTRAINT(FbcUserDefinedConstraintComponentCoefficientMustBeParameter, UserDefinedConstraintComponent, udcc) +{ + pre(udcc.isSetCoefficient()); + + std::string as = udcc.getCoefficient(); + + bool fail = false; + + msg = "The with id '"; + msg += udcc.getId(); + msg += "' refers to a parameter '"; + msg += as; + msg += "' that does not exist within the ."; + + if (m.getParameter(as) == NULL) + { + fail = true; + } + + inv(fail == false); +} +END_CONSTRAINT + // 21305 START_CONSTRAINT(FbcUserDefinedConstraintComponentVariableMustBeReactionOrParameter, UserDefinedConstraintComponent, udcc) @@ -853,7 +907,33 @@ START_CONSTRAINT(FbcUserDefinedConstraintComponentVariableMustBeReactionOrParame END_CONSTRAINT // 21306 - caught at read -// 21307 - sring +// 21307 - string + +// 21308 +START_CONSTRAINT(FbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter, UserDefinedConstraintComponent, udcc) +{ + pre(udcc.isSetVariable2()); + + std::string as = udcc.getVariable2(); + + bool fail = false; + + msg = "The with id '"; + msg += udcc.getId(); + msg += "' refers to a variable2 '"; + msg += as; + msg += "' that does not exist within the ."; + + if (m.getReaction(as) == NULL && m.getParameter(as) == NULL) + { + fail = true; + } + + inv(fail == false); +} +END_CONSTRAINT + + // 21401 - caught at read // 21402 - caught at read diff --git a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx index 0c075682e3..ff39717578 100644 --- a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx +++ b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx @@ -48,6 +48,8 @@ addConstraint(new VConstraintFluxObjectiveFbcFluxObjectReactionMustExist(*this)) addConstraint(new VConstraintFluxObjectiveFbcFluxObjectCoefficientWhenStrict(*this)); +addConstraint(new VConstraintFluxObjectiveFbcFluxObjectReaction2MustExist(*this)); + addConstraint(new VConstraintReactionFbcReactionLwrBoundRefExists(*this)); addConstraint(new VConstraintReactionFbcReactionUpBoundRefExists(*this)); @@ -84,8 +86,12 @@ addConstraint(new UniqueGeneProductLabels(FbcGeneProductLabelMustBeUnique, *this addConstraint(new VConstraintGeneProductFbcGeneProductAssocSpeciesMustExist(*this)); +addConstraint(new VConstraintUserDefinedConstraintComponentFbcUserDefinedConstraintComponentCoefficientMustBeParameter(*this)); + addConstraint(new VConstraintUserDefinedConstraintComponentFbcUserDefinedConstraintComponentVariableMustBeReactionOrParameter(*this)); +addConstraint(new VConstraintUserDefinedConstraintComponentFbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter(*this)); + addConstraint(new VConstraintUserDefinedConstraintFbcUserDefinedConstraintLowerBoundMustBeParameter(*this)); addConstraint(new VConstraintUserDefinedConstraintFbcUserDefinedConstraintUpperBoundMustBeParameter(*this)); diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml index 7b1a464f3d..c07d0c43e1 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml index 97d1e172af..41dabf5830 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml index fdfd0f5d54..be9eb3217f 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml index 52e2749368..00db78cbf0 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml index ae0e9198c2..d79c6e883a 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml index 00ba00c5aa..1ed5e144fd 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml index bfb1c4ddfb..695370d385 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml index ccf42db1ac..12b604f1f9 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021304-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021304-fail-01-01.xml deleted file mode 100644 index 0edb76efb9..0000000000 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021304-fail-01-01.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - k - S1 - - - - - - - - - - - - - - - - - - - k - S2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml index 91d01b97bb..c013a92f89 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml index 838d64f7fc..acf02cd1ca 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml index e1b61fc2f0..b2e83d10f1 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml index fd1767b838..0827303736 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml index 97f00c5129..5b919a0b60 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml index 5ca442321a..122c0545ab 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml index 3f4823dec4..d802d00b5f 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml index a8beb24d0f..0c7c176d50 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml index 130d6860e3..aa3ab7c9d1 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml index 0467bf3491..5df88201a7 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml index 378615e533..148584f896 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml index 78385bf1ee..8eb5fe3936 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml index 7ab407d093..aa858dd0dd 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml @@ -107,7 +107,7 @@ - + day2.c9 diff --git a/src/sbml/packages/multi/extension/MultiListOfReactionsPlugin.cpp b/src/sbml/packages/multi/extension/MultiListOfReactionsPlugin.cpp index ae4304c333..af94d9b7f8 100644 --- a/src/sbml/packages/multi/extension/MultiListOfReactionsPlugin.cpp +++ b/src/sbml/packages/multi/extension/MultiListOfReactionsPlugin.cpp @@ -137,7 +137,7 @@ MultiListOfReactionsPlugin::createObject (XMLInputStream& stream) object = new IntraSpeciesReaction(multins); delete multins; } - catch (SBMLConstructorException*) + catch (SBMLConstructorException &) { object = new IntraSpeciesReaction(SBMLDocument::getDefaultLevel(), SBMLDocument::getDefaultVersion()); diff --git a/src/sbml/packages/multi/extension/test/TestMultiExtension.cpp b/src/sbml/packages/multi/extension/test/TestMultiExtension.cpp index 07a539b7db..d36d5ce71f 100644 --- a/src/sbml/packages/multi/extension/test/TestMultiExtension.cpp +++ b/src/sbml/packages/multi/extension/test/TestMultiExtension.cpp @@ -314,6 +314,19 @@ START_TEST(test_MultiExtension_read) } END_TEST +START_TEST(test_multi_issue_338) +{ + string filename(TestDataDirectory); + string cfile = filename + "issue_338.xml"; + SBMLDocument* doc = readSBMLFromFile(cfile.c_str()); + SBMLDocument* clone = doc->clone(); + clone->validateSBML(); + fail_unless(clone->getNumErrors(LIBSBML_SEV_ERROR) == 3); + + delete clone; + delete doc; +} +END_TEST Suite * create_suite_MultiExtension(void) @@ -334,6 +347,7 @@ create_suite_MultiExtension(void) tcase_add_test(tcase, test_MultiExtension_typecode); tcase_add_test(tcase, test_MultiExtension_SBMLtypecode); tcase_add_test(tcase, test_MultiExtension_read); + tcase_add_test(tcase, test_multi_issue_338); suite_add_tcase(suite, tcase); diff --git a/src/sbml/packages/multi/extension/test/test-data/issue_338.xml b/src/sbml/packages/multi/extension/test/test-data/issue_338.xml new file mode 100644 index 0000000000..2cf4a20b03 --- /dev/null +++ b/src/sbml/packages/multi/extension/test/test-data/issue_338.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/sbml/packages/multi/validator/constraints/MultiConsistencyConstraints.cpp b/src/sbml/packages/multi/validator/constraints/MultiConsistencyConstraints.cpp index afa8b86786..14cfae9e34 100644 --- a/src/sbml/packages/multi/validator/constraints/MultiConsistencyConstraints.cpp +++ b/src/sbml/packages/multi/validator/constraints/MultiConsistencyConstraints.cpp @@ -1119,7 +1119,7 @@ START_CONSTRAINT (MultiSpeFtrVal_ValAtt_Ref, SpeciesFeatureValue, speciesFeature // species const Species * species = dynamic_cast(sbaseSpecies); - if (species == NULL) { // possible from subListOfSpeciesFeatures? + if (species == NULL && sbaseSpecies != NULL) { // possible from subListOfSpeciesFeatures? species = dynamic_cast(sbaseSpecies->getParentSBMLObject()); } diff --git a/src/sbml/packages/render/sbml/DefaultValues.cpp b/src/sbml/packages/render/sbml/DefaultValues.cpp index 12a5add2fb..7bfff15317 100644 --- a/src/sbml/packages/render/sbml/DefaultValues.cpp +++ b/src/sbml/packages/render/sbml/DefaultValues.cpp @@ -3777,7 +3777,7 @@ LIBSBML_EXTERN char * DefaultValues_getFillRuleAsString(const DefaultValues_t * dv) { - return (char *)(dv->getFillRuleAsString()).c_str(); + return (char *)safe_strdup(FillRule_toString((FillRule_t)(dv->getFillRule()))); } diff --git a/src/sbml/test/TestRunner.c b/src/sbml/test/TestRunner.c index a7a7d35a37..4a97c1ef0a 100644 --- a/src/sbml/test/TestRunner.c +++ b/src/sbml/test/TestRunner.c @@ -117,6 +117,7 @@ Suite *create_suite_SBMLConvertStrict (void); Suite *create_suite_SBMLConvertFromL3V2 (void); Suite *create_suite_SBMLDocument (void); Suite *create_suite_SBMLError (void); +Suite *create_suite_SBMLErrorLog (void); Suite *create_suite_SBMLReader (void); Suite *create_suite_SBMLWriter (void); Suite *create_suite_SimpleSpeciesReference (void); @@ -223,6 +224,7 @@ main (int argc, char* argv[]) int num_failed; setTestDataDirectory(); + //SRunner *runner = srunner_create(create_suite_SBMLErrorLog()); SRunner *runner = srunner_create( create_suite_ReadSBML () ); srunner_add_suite( runner, create_suite_SBMLValidatorAPI () ); @@ -298,6 +300,7 @@ main (int argc, char* argv[]) srunner_add_suite( runner, create_suite_SBMLConvertFromL3V2 () ); srunner_add_suite( runner, create_suite_SBMLDocument () ); srunner_add_suite( runner, create_suite_SBMLError () ); + srunner_add_suite( runner, create_suite_SBMLErrorLog () ); srunner_add_suite( runner, create_suite_TestReadFromFile1 () ); srunner_add_suite( runner, create_suite_TestReadFromFile2 () ); srunner_add_suite( runner, create_suite_TestReadFromFile3 () ); diff --git a/src/sbml/test/TestSBMLErrorLog.c b/src/sbml/test/TestSBMLErrorLog.c new file mode 100644 index 0000000000..85056fc633 --- /dev/null +++ b/src/sbml/test/TestSBMLErrorLog.c @@ -0,0 +1,181 @@ +/** + * \file TestErrorLog.c + * \brief ErrorLog unit tests + * \author Ben Bornstein + * + * */ + +#include + +#include +#include +#include +#include +#include +#include + +#include + + + +#include + +LIBSBML_CPP_NAMESPACE_USE + + +BEGIN_C_DECLS + +extern char *TestDataDirectory; + +START_TEST(test_SBMLErrorLog_removeAll) +{ + SBMLErrorLog_t *log = SBMLErrorLog_create(); + XMLError_t *e = XMLError_createWithIdAndMessage(1234, "1"); + + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + + fail_unless(SBMLErrorLog_contains(log, 1234) == 1); + fail_unless(SBMLErrorLog_getNumErrors(log) == 4); + + SBMLErrorLog_remove(log, 1234); + fail_unless(SBMLErrorLog_contains(log, 1234) == 1); + fail_unless(SBMLErrorLog_getNumErrors(log) == 3); + + SBMLErrorLog_removeAll(log, 1234); + fail_unless(SBMLErrorLog_contains(log, 1234) == 0); + fail_unless(SBMLErrorLog_getNumErrors(log) == 0); + + XMLError_free(e); + SBMLErrorLog_free(log); + +} +END_TEST + + +START_TEST(test_SBMLErrorLog_add_clear) +{ + SBMLErrorLog_t *log = SBMLErrorLog_create(); + XMLError_t *e = XMLError_createWithIdAndMessage(1234, "1"); + XMLError_t *e1 = XMLError_createWithIdAndMessage(2345, "1"); + + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + SBMLErrorLog_add(log, (const SBMLError_t*)(e1)); + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + + fail_unless(SBMLErrorLog_contains(log, 1234) == 1); + fail_unless(SBMLErrorLog_contains(log, 2345) == 1); + fail_unless(SBMLErrorLog_getNumErrors(log) == 4); + + SBMLErrorLog_remove(log, 2345); + fail_unless(SBMLErrorLog_contains(log, 1234) == 1); + fail_unless(SBMLErrorLog_contains(log, 2345) == 0); + fail_unless(SBMLErrorLog_getNumErrors(log) == 3); + + SBMLErrorLog_clearLog(log); + fail_unless(SBMLErrorLog_getNumErrors(log) == 0); + + XMLError_free(e); + XMLError_free(e1); + SBMLErrorLog_free(log); +} +END_TEST + + +START_TEST(test_SBMLErrorLog_get) +{ + SBMLErrorLog_t *log = SBMLErrorLog_create(); + XMLError_t *e = XMLError_createWithIdAndMessage(1234, "1"); + + SBMLErrorLog_add(log, (const SBMLError_t*)(e)); + + // here the xmlerror is merely cast as an sbmlerror + // it is added to the log as an xmlerror + fail_unless(SBMLErrorLog_getNumErrors(log) == 1); + + // the dynamic cast on return fails + const SBMLError_t* r = SBMLErrorLog_getError(log, 1); + fail_unless(r == NULL); + + XMLError_free(e); + SBMLErrorLog_free(log); +} +END_TEST + +START_TEST(test_SBMLErrorLog_type) +{ + SBMLDocument_t *d; + + char *filename = safe_strcat(TestDataDirectory, "01006-fail-01-13.xml"); + + d = readSBML(filename); + + unsigned int n = SBMLDocument_validateSBML(d); + const SBMLErrorLog_t *log = SBMLDocument_getErrorLog(d); + const SBMLError_t* r = SBMLErrorLog_getError(log, 0); + + // the error is an xmlerror but does get correctly cast to sbmlerror + fail_unless(r != NULL); + + SBMLDocument_free(d); + safe_free((char*)(filename)); +} +END_TEST + + + +Suite * +create_suite_SBMLErrorLog (void) +{ + Suite *suite = suite_create("ErrorLog"); + TCase *tcase = tcase_create("ErrorLog"); + + tcase_add_test(tcase, test_SBMLErrorLog_removeAll); + tcase_add_test(tcase, test_SBMLErrorLog_add_clear); + tcase_add_test(tcase, test_SBMLErrorLog_get); + tcase_add_test(tcase, test_SBMLErrorLog_type); + + suite_add_tcase(suite, tcase); + + return suite; +} + +END_C_DECLS + diff --git a/src/sbml/test/TestWriteSBML.cpp b/src/sbml/test/TestWriteSBML.cpp index db1f1bb41d..a5f3bb73aa 100644 --- a/src/sbml/test/TestWriteSBML.cpp +++ b/src/sbml/test/TestWriteSBML.cpp @@ -129,6 +129,18 @@ START_TEST (test_WriteSBML_error) END_TEST +START_TEST(test_WriteSBML_NULL_doc) +{ + SBMLDocument *d = NULL; + SBMLWriter *w = new SBMLWriter(); + + fail_unless(!w->writeSBML(d, "/tmp/")); + + delete w; +} +END_TEST + + START_TEST (test_SBMLWriter_create) { SBMLWriter_t *w = SBMLWriter_create(); @@ -3268,6 +3280,7 @@ create_suite_WriteSBML () // Basic writing capability tcase_add_test( tcase, test_WriteSBML_error ); + tcase_add_test(tcase, test_WriteSBML_NULL_doc); // SBMLDocument tcase_add_test( tcase, test_WriteSBML_SBMLDocument_L1v1 ); diff --git a/src/sbml/test/test-data/01006-fail-01-13.xml b/src/sbml/test/test-data/01006-fail-01-13.xml new file mode 100644 index 0000000000..b881ce034f --- /dev/null +++ b/src/sbml/test/test-data/01006-fail-01-13.xml @@ -0,0 +1 @@ + diff --git a/src/sbml/validator/constraints/FunctionApplyMathCheck.cpp b/src/sbml/validator/constraints/FunctionApplyMathCheck.cpp index 7176d9faf7..f7a3bd16a3 100644 --- a/src/sbml/validator/constraints/FunctionApplyMathCheck.cpp +++ b/src/sbml/validator/constraints/FunctionApplyMathCheck.cpp @@ -120,10 +120,19 @@ FunctionApplyMathCheck::checkMath (const Model& m, const ASTNode& node, const SB checkChildren(m, node, sb); break; - } } +void +FunctionApplyMathCheck::checkFunctionDefinition(const Model& m, const ASTNode& node, + const SBase & sb) +{ + // a missing fd is caught by 20301 for l2v3 and lower + if (m.getLevel() > 2 || (m.getLevel() == 2 && m.getVersion() > 3)) + { + checkMath(m, node, sb); + } +} /* * Checks that the functionDefinition referred to by a <ci> element exists diff --git a/src/sbml/validator/constraints/FunctionApplyMathCheck.h b/src/sbml/validator/constraints/FunctionApplyMathCheck.h index 3cf91171f8..59decd9cc9 100644 --- a/src/sbml/validator/constraints/FunctionApplyMathCheck.h +++ b/src/sbml/validator/constraints/FunctionApplyMathCheck.h @@ -86,6 +86,14 @@ class FunctionApplyMathCheck: public MathMLBase */ virtual void checkMath (const Model& m, const ASTNode& node, const SBase & sb); + /** + * Checks the MathML of the ASTnode for FunctionDefinitions + * is appropriate for the function being performed + * + * If an inconsistency is found, an error message is logged. + */ + virtual void checkFunctionDefinition(const Model& m, const ASTNode& node, const SBase & sb); + /** * Returns the preamble to use when logging constraint violations. * diff --git a/src/sbml/validator/constraints/MathMLBase.cpp b/src/sbml/validator/constraints/MathMLBase.cpp index 2e7b3087e7..510f17f292 100644 --- a/src/sbml/validator/constraints/MathMLBase.cpp +++ b/src/sbml/validator/constraints/MathMLBase.cpp @@ -219,8 +219,25 @@ MathMLBase::check_ (const Model& m, const Model& object) checkMath(m, *m.getConstraint(n)->getMath(), *m.getConstraint(n)); } } + + + for (n = 0; n < m.getNumFunctionDefinitions(); n++) + { + if (m.getFunctionDefinition(n)->isSetMath()) + { + checkFunctionDefinition(m, *m.getFunctionDefinition(n)->getMath(), *m.getFunctionDefinition(n)); + } + } + } +void +MathMLBase::checkFunctionDefinition(const Model& m, + const ASTNode& node, + const SBase & sb) +{ + return; +} /* * Checks the MathML of the children of ASTnode diff --git a/src/sbml/validator/constraints/MathMLBase.h b/src/sbml/validator/constraints/MathMLBase.h index 4fe333d79b..8b46b6c160 100644 --- a/src/sbml/validator/constraints/MathMLBase.h +++ b/src/sbml/validator/constraints/MathMLBase.h @@ -96,6 +96,14 @@ class MathMLBase: public TConstraint */ virtual void checkMath (const Model& m, const ASTNode& node, const SBase & sb) = 0; + /** + * Checks the MathML of the ASTnode for FunctionDefinitions + * is appropriate for the function being performed + * + * If an inconsistency is found, an error message is logged. + */ + virtual void checkFunctionDefinition(const Model& m, const ASTNode& node, const SBase & sb); + /** * Checks the MathML of the children of ASTnode * forces recursion through the AST tree diff --git a/src/sbml/validator/constraints/RateOfCompartmentMathCheck.cpp b/src/sbml/validator/constraints/RateOfCompartmentMathCheck.cpp index b9743091b1..37a8740068 100644 --- a/src/sbml/validator/constraints/RateOfCompartmentMathCheck.cpp +++ b/src/sbml/validator/constraints/RateOfCompartmentMathCheck.cpp @@ -214,7 +214,7 @@ RateOfCompartmentMathCheck::getMessage (const ASTNode& node, const SBase& object } break; } - oss_msg << "uses the species'" << node.getChild(0)->getName(); + oss_msg << "uses the species '" << node.getChild(0)->getName(); oss_msg << "' whose compartment is referenced as the variable in an assignmentRule."; safe_free(formula); diff --git a/src/sbml/validator/test/test-data/libsbml-constraints/99219-fail-01-30.xml b/src/sbml/validator/test/test-data/libsbml-constraints/99219-fail-01-30-10214.xml similarity index 100% rename from src/sbml/validator/test/test-data/libsbml-constraints/99219-fail-01-30.xml rename to src/sbml/validator/test/test-data/libsbml-constraints/99219-fail-01-30-10214.xml diff --git a/src/sbml/validator/test/test-data/sbml-mathml-constraints/10214-fail-01-08.xml b/src/sbml/validator/test/test-data/sbml-mathml-constraints/10214-fail-01-08.xml new file mode 100644 index 0000000000..ae2949ab17 --- /dev/null +++ b/src/sbml/validator/test/test-data/sbml-mathml-constraints/10214-fail-01-08.xml @@ -0,0 +1,17 @@ + + + + + + + + + undefined_function + 0.5 + + + + + + + \ No newline at end of file