Skip to content

Commit

Permalink
Allow l1v5 namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
luciansmith committed Dec 22, 2023
1 parent 447cc05 commit 1617a73
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/sedml/SedBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ SedBase::read (LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream)
if (i > -1)
{
std::string uri = xmlns->getURI(i);
if (uri == SEDML_XMLNS_L1V1 || uri == SEDML_XMLNS_L1V2 || uri == SEDML_XMLNS_L1V3 || uri == SEDML_XMLNS_L1V4)
if (uri == SEDML_XMLNS_L1V1 || uri == SEDML_XMLNS_L1V2 || uri == SEDML_XMLNS_L1V3 || uri == SEDML_XMLNS_L1V4 || uri == SEDML_XMLNS_L1V5)
{
error = false;
}
Expand Down
12 changes: 10 additions & 2 deletions src/sedml/SedDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3204,8 +3204,12 @@ SedDocument::writeXMLNS(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
xmlns.add(SEDML_XMLNS_L1V2);
else if (getVersion() == 3)
xmlns.add(SEDML_XMLNS_L1V3);
else
else if (getVersion() == 4)
xmlns.add(SEDML_XMLNS_L1V4);
else if (getVersion() == 5)
xmlns.add(SEDML_XMLNS_L1V5);
else
xmlns.add(SEDML_XMLNS_L1V5);

mSedNamespaces->setNamespaces(&xmlns);
thisNs = const_cast<LIBSBML_CPP_NAMESPACE_QUALIFIER XMLNamespaces *>(getNamespaces());
Expand All @@ -3218,8 +3222,12 @@ SedDocument::writeXMLNS(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
thisNs->add(SEDML_XMLNS_L1V2);
else if (getVersion() == 3)
thisNs->add(SEDML_XMLNS_L1V3);
else
else if (getVersion() == 4)
thisNs->add(SEDML_XMLNS_L1V4);
else if (getVersion() == 5)
thisNs->add(SEDML_XMLNS_L1V5);
else
thisNs->add(SEDML_XMLNS_L1V5);
}
else
{
Expand Down
24 changes: 24 additions & 0 deletions src/sedml/SedNamespaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ SedNamespaces::initSedNamespace()
case 4:
mNamespaces->add(SEDML_XMLNS_L1V4);
break;
case 5:
mNamespaces->add(SEDML_XMLNS_L1V5);
break;
}
break;
}
Expand Down Expand Up @@ -129,6 +132,7 @@ SedNamespaces::getSupportedNamespaces()
result->add(new SedNamespaces(1,2));
result->add(new SedNamespaces(1,3));
result->add(new SedNamespaces(1,4));
result->add(new SedNamespaces(1,5));
return result;
}

Expand Down Expand Up @@ -201,6 +205,9 @@ SedNamespaces::getSedNamespaceURI(unsigned int level,
case 4:
uri = SEDML_XMLNS_L1V4;
break;
case 5:
uri = SEDML_XMLNS_L1V5;
break;
}
break;
}
Expand Down Expand Up @@ -358,6 +365,12 @@ SedNamespaces::isValidCombination()
declaredURI.assign(SEDML_XMLNS_L1V4);
}

if (xmlns->hasURI(SEDML_XMLNS_L1V5))
{
++numNS;
declaredURI.assign(SEDML_XMLNS_L1V5);
}

// checks if the SED-ML Namespace is explicitly defined.
for (int i=0; i < xmlns->getLength(); i++)
{
Expand Down Expand Up @@ -420,6 +433,17 @@ SedNamespaces::isValidCombination()
}
}
break;
case 5:
// the namespaces contains the sedml namespaces
// check it is the correct ns for the level/version
if (sedmlDeclared)
{
if (declaredURI != string(SEDML_XMLNS_L1V5))
{
valid = false;
}
}
break;
default:
valid = false;
break;
Expand Down
4 changes: 3 additions & 1 deletion src/sedml/SedNamespaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
namespace LIBSEDML_CPP_NAMESPACE
{
const unsigned int SEDML_DEFAULT_LEVEL = 1;
const unsigned int SEDML_DEFAULT_VERSION = 3;
const unsigned int SEDML_DEFAULT_VERSION = 5;
const char* const SEDML_XMLNS_L1V1 = "http://sed-ml.org/";
const char* const SEDML_XMLNS_L1V2 = "http://sed-ml.org/sed-ml/level1/version2";
const char* const SEDML_XMLNS_L1V3 = "http://sed-ml.org/sed-ml/level1/version3";
const char* const SEDML_XMLNS_L1V4 = "http://sed-ml.org/sed-ml/level1/version4";
const char* const SEDML_XMLNS_L1V5 = "http://sed-ml.org/sed-ml/level1/version5";
}
#else
static const unsigned int SEDML_DEFAULT_LEVEL = 1;
Expand All @@ -62,6 +63,7 @@ static const char* const SEDML_XMLNS_L1V1 = "http://sed-ml.org/";
static const char* const SEDML_XMLNS_L1V2 = "http://sed-ml.org/sed-ml/level1/version2";
static const char* const SEDML_XMLNS_L1V3 = "http://sed-ml.org/sed-ml/level1/version3";
static const char* const SEDML_XMLNS_L1V4 = "http://sed-ml.org/sed-ml/level1/version4";
static const char* const SEDML_XMLNS_L1V5 = "http://sed-ml.org/sed-ml/level1/version5";
#endif

#ifdef __cplusplus
Expand Down
25 changes: 25 additions & 0 deletions tests/TestIssues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,31 @@ TEST_CASE("Reading / Writing L1V4", "[sedml]")
delete doc;
}

TEST_CASE("Reading / Writing L1V5", "[sedml]")
{
std::string fileName = getTestFile("/test-data/noble_1962_local.sedml");
SedDocument* doc = readSedMLFromFile(fileName.c_str());
REQUIRE (doc->getNumErrors(LIBSEDML_SEV_ERROR) == 0);


// convert to l1v5
doc->setLevel(1); doc->setVersion(5);

// write to string
SedWriter sw;
std::string l1v5 = sw.writeSedMLToStdString(doc);
REQUIRE(l1v5.find("version=\"5\"") != std::string::npos);

// don't need doc anymore
delete doc;

// read back
doc = readSedMLFromString(l1v5.c_str());
REQUIRE(doc->getNumErrors(LIBSEDML_SEV_ERROR) == 0);

delete doc;
}

TEST_CASE("Reading L1V4 curve should not require logY", "[sedml]")
{
std::string fileName = getTestFile("/test-data/issue_63.sedml");
Expand Down

0 comments on commit 1617a73

Please sign in to comment.