Skip to content

Commit

Permalink
Issue331 (#336)
Browse files Browse the repository at this point in the history
* #331 Update the version scheme
* #331 Update the minimum version required
  • Loading branch information
kaizu authored Mar 1, 2019
1 parent 133985d commit d66e665
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 19 deletions.
2 changes: 1 addition & 1 deletion ecell4/bd/BDWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class BDWorld
boost::scoped_ptr<H5::H5File>
fin(new H5::H5File(filename.c_str(), H5F_ACC_RDONLY));

const std::string required = "ecell4-bd-1.0.0";
const std::string required = "ecell4-bd-0.0";
try
{
const std::string version = extras::load_version_information(*fin);
Expand Down
36 changes: 26 additions & 10 deletions ecell4/core/extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ VersionInformation parse_version_information(const std::string& version)
#else /* WIN32_MSC */
using namespace std::tr1;
#endif /* HAVE_BOOST_REGEX */
regex reg("^([^-\\.]+-[^-\\.]+-)([0123456789]+)\\.([0123456789]+)\\.(dev|)([0123456789]+)$");
regex reg("^([^-\\.]+-[^-\\.]+-)([0123456789]+)\\.([0123456789]+)(\\.[0123456789]+|)(\\.dev[0123456789]+|)$");
smatch result;
if (!regex_match(version, result, reg))
{
Expand All @@ -119,13 +119,14 @@ VersionInformation parse_version_information(const std::string& version)
const std::string header = result.str(1);
const int majorno = mystoi(result.str(2));
const int minorno = mystoi(result.str(3));
const int patchno = mystoi(result.str(5));
const int patchno = (result.str(4).size() > 1 ? mystoi(result.str(4).substr(1)) : -1);
const int devno = (result.str(5).size() > 4 ? mystoi(result.str(5).substr(4)) : -1);

return VersionInformation(header, majorno, minorno, patchno);
return VersionInformation(header, majorno, minorno, patchno, devno);
#else /* regex.h */
regex_t reg;
int errcode = regcomp(
&reg, "^([^-\\.]+-[^-\\.]+-)([0123456789]+)\\.([0123456789]+)\\.(dev|)([0123456789]+)$",
&reg, "^([^-\\.]+-[^-\\.]+-)([0123456789]+)\\.([0123456789]+)(\\.[0123456789]+|)(\\.dev[0123456789]+|)$",
REG_EXTENDED);
if (errcode != 0)
{
Expand All @@ -150,21 +151,36 @@ VersionInformation parse_version_information(const std::string& version)
const std::string header = version.substr(match[1].rm_so, match[1].rm_eo - match[1].rm_so);
const int majorno = mystoi(version.substr(match[2].rm_so, match[2].rm_eo - match[2].rm_so));
const int minorno = mystoi(version.substr(match[3].rm_so, match[3].rm_eo - match[3].rm_so));
const int patchno = mystoi(version.substr(match[4].rm_so, match[5].rm_eo - match[5].rm_so));
const int patchno = (match[4].rm_eo - match[4].rm_so > 0 ? mystoi(version.substr(match[4].rm_so + 1)) : -1);
const int devno = (match[5].rm_eo - match[5].rm_so > 0 ? mystoi(version.substr(match[5].rm_so + 4)) : -1);

regfree(&reg);
return VersionInformation(header, majorno, minorno, patchno);
return VersionInformation(header, majorno, minorno, patchno, devno);
#endif /* HAVE_BOOST_REGEX */
}

bool check_version_information(const std::string& version, const std::string& required)
{
const VersionInformation vinfo1(parse_version_information(version));
const VersionInformation vinfo2(parse_version_information(required));
return (vinfo1.header == vinfo2.header
&& vinfo1.majorno >= vinfo2.majorno
&& vinfo1.minorno >= vinfo2.minorno
&& vinfo1.patchno >= vinfo2.patchno);

if (vinfo1.header != vinfo2.header)
{
return false;
}
else if (vinfo1.majorno != vinfo2.majorno)
{
return (vinfo1.majorno >= vinfo2.majorno);
}
else if (vinfo1.minorno != vinfo2.minorno)
{
return (vinfo1.minorno >= vinfo2.minorno);
}
else if (vinfo1.patchno != vinfo2.patchno)
{
return (vinfo1.patchno == -1 || (vinfo2.patchno != -1 && vinfo1.patchno >= vinfo2.patchno));
}
return (vinfo1.devno == -1 || (vinfo2.devno != -1 && vinfo1.devno >= vinfo2.devno));
}

} // extras
Expand Down
6 changes: 3 additions & 3 deletions ecell4/core/extras.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ get_dimension_from_model(const Species& species, const boost::shared_ptr<Model>&
struct VersionInformation
{
std::string header;
int majorno, minorno, patchno;
int majorno, minorno, patchno, devno;

VersionInformation(
const std::string& header, const int majorno, const int minorno, const int patchno)
: header(header), majorno(majorno), minorno(minorno), patchno(patchno)
const std::string& header, const int majorno, const int minorno, const int patchno, const int devno)
: header(header), majorno(majorno), minorno(minorno), patchno(patchno), devno(devno)
{
;
}
Expand Down
42 changes: 42 additions & 0 deletions ecell4/core/tests/extras_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,45 @@ BOOST_AUTO_TEST_CASE(DimensionAttributeTest)
BOOST_CHECK_EQUAL(extras::get_dimension_from_model(Species("D"), model), Shape::TWO);
BOOST_CHECK_THROW(extras::get_dimension_from_model(Species("E"), model), NotFound);
}

BOOST_AUTO_TEST_CASE(VersionInformationTest)
{
{
const extras::VersionInformation vinfo1 = extras::parse_version_information("ecell4-test-1.2.3");
BOOST_CHECK_EQUAL(vinfo1.header, "ecell4-test-");
BOOST_CHECK_EQUAL(vinfo1.majorno, 1);
BOOST_CHECK_EQUAL(vinfo1.minorno, 2);
BOOST_CHECK_EQUAL(vinfo1.patchno, 3);
BOOST_CHECK_EQUAL(vinfo1.devno, -1);
}
{
const extras::VersionInformation vinfo1 = extras::parse_version_information("ecell4-test-1.2");
BOOST_CHECK_EQUAL(vinfo1.header, "ecell4-test-");
BOOST_CHECK_EQUAL(vinfo1.majorno, 1);
BOOST_CHECK_EQUAL(vinfo1.minorno, 2);
BOOST_CHECK_EQUAL(vinfo1.patchno, -1);
BOOST_CHECK_EQUAL(vinfo1.devno, -1);
}
{
const extras::VersionInformation vinfo1 = extras::parse_version_information("ecell4-test-1.2.dev4");
BOOST_CHECK_EQUAL(vinfo1.header, "ecell4-test-");
BOOST_CHECK_EQUAL(vinfo1.majorno, 1);
BOOST_CHECK_EQUAL(vinfo1.minorno, 2);
BOOST_CHECK_EQUAL(vinfo1.patchno, -1);
BOOST_CHECK_EQUAL(vinfo1.devno, 4);
}

{
BOOST_CHECK(extras::check_version_information("ecell4-test-1.0", "ecell4-test-1.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.1", "ecell4-test-1.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-2.0.0", "ecell4-test-1.0"));
BOOST_CHECK(!extras::check_version_information("ecell4-test-1.0.0", "ecell4-test-1.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.0.0", "ecell4-test-1.0.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.0.1", "ecell4-test-1.0.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.0", "ecell4-test-1.0.0"));
BOOST_CHECK(!extras::check_version_information("ecell4-test-1.0.dev1", "ecell4-test-1.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.1.dev1", "ecell4-test-1.0"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.0.dev1", "ecell4-test-1.0.dev1"));
BOOST_CHECK(extras::check_version_information("ecell4-test-1.0.dev2", "ecell4-test-1.0.dev1"));
}
}
2 changes: 1 addition & 1 deletion ecell4/egfrd/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class World
boost::scoped_ptr<H5::H5File>
fin(new H5::H5File(filename.c_str(), H5F_ACC_RDONLY));

const std::string required = "ecell4-egfrd-1.0.0";
const std::string required = "ecell4-egfrd-0.0";
try
{
const std::string version = ecell4::extras::load_version_information(*fin);
Expand Down
2 changes: 1 addition & 1 deletion ecell4/gillespie/GillespieWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class GillespieWorld
boost::scoped_ptr<H5::H5File>
fin(new H5::H5File(filename.c_str(), H5F_ACC_RDONLY));

const std::string required = "ecell4-gillespie-1.0.0";
const std::string required = "ecell4-gillespie-0.0";
try
{
const std::string version = extras::load_version_information(*fin);
Expand Down
2 changes: 1 addition & 1 deletion ecell4/meso/MesoscopicWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class MesoscopicWorld
boost::scoped_ptr<H5::H5File>
fin(new H5::H5File(filename.c_str(), H5F_ACC_RDONLY));

const std::string required = "ecell4-meso-1.0.0";
const std::string required = "ecell4-meso-0.0";
try
{
const std::string version = extras::load_version_information(*fin);
Expand Down
2 changes: 1 addition & 1 deletion ecell4/ode/ODEWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void ODEWorld::load(const std::string& filename)
boost::scoped_ptr<H5::H5File>
fin(new H5::H5File(filename.c_str(), H5F_ACC_RDONLY));

const std::string required = "ecell4-ode-1.0.0";
const std::string required = "ecell4-ode-0.0";
try
{
const std::string version = extras::load_version_information(*fin);
Expand Down
2 changes: 1 addition & 1 deletion ecell4/spatiocyte/SpatiocyteWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SpatiocyteWorld
boost::scoped_ptr<H5::H5File>
fin(new H5::H5File(filename.c_str(), H5F_ACC_RDONLY));

const std::string required = "ecell4-spatiocyte-1.0.0";
const std::string required = "ecell4-spatiocyte-0.0";
try
{
const std::string version = extras::load_version_information(*fin);
Expand Down

0 comments on commit d66e665

Please sign in to comment.