diff --git a/hdt-lib/include/HDTVersion.hpp b/hdt-lib/include/HDTVersion.hpp index dca46b08..3ce7fa88 100644 --- a/hdt-lib/include/HDTVersion.hpp +++ b/hdt-lib/include/HDTVersion.hpp @@ -27,6 +27,9 @@ * The total version number is: v.. */ + #ifndef HDT_HDTVERSION_HPP_ + #define HDT_HDTVERSION_HPP_ + // Version of the actual HDT file that is generated or read. // Software must be backwards compatible with all HDT files with the same number. #define HDT_VERSION "1" @@ -37,3 +40,14 @@ // Subreleases that are backwards compatible with both HDT and index file #define RELEASE_VERSION "1" + +#include + +namespace hdt { +namespace HDTVersion { + inline std::string get_version_string(std::string delimiter) { + return std::string("v") + HDT_VERSION + delimiter + INDEX_VERSION + delimiter + RELEASE_VERSION; + }; +} +} +#endif /* HDT_HDTVERSION_HPP_ */ diff --git a/hdt-lib/include/HDTVocabulary.hpp b/hdt-lib/include/HDTVocabulary.hpp index 86f0d583..ed196169 100644 --- a/hdt-lib/include/HDTVocabulary.hpp +++ b/hdt-lib/include/HDTVocabulary.hpp @@ -39,7 +39,8 @@ namespace hdt { namespace HDTVocabulary { // Base const std::string HDT_BASE = ""; + const std::string HDT_CONTAINER = HDT_BASE+"HDTv" + HDTVersion::get_version_string("-") + ">"; + const std::string HDT_CONTAINER_BASE = HDT_BASE+"HDTv" + HDT_VERSION; const std::string HDT_HEADER = HDT_BASE+"header"; const std::string HDT_DICTIONARY_BASE = HDT_BASE+"dictionary"; const std::string HDT_DICTIONARY = HDT_DICTIONARY_BASE+">"; diff --git a/hdt-lib/src/hdt/BasicHDT.cpp b/hdt-lib/src/hdt/BasicHDT.cpp index 7a25e39f..d51403bc 100644 --- a/hdt-lib/src/hdt/BasicHDT.cpp +++ b/hdt-lib/src/hdt/BasicHDT.cpp @@ -656,8 +656,9 @@ void BasicHDT::loadFromHDT(std::istream & input, ProgressListener *listener) // Load Global ControlInformation. controlInformation.load(input); std::string hdtFormat = controlInformation.getFormat(); - if(hdtFormat!=HDTVocabulary::HDT_CONTAINER) { - throw std::runtime_error("This software cannot open this version of HDT File (" + hdtFormat + " =/= " + HDTVocabulary::HDT_CONTAINER + ")"); + //if(hdtFormat!=HDTVocabulary::HDT_CONTAINER) { + if (hdtFormat.find(HDTVocabulary::HDT_CONTAINER_BASE) == std::string::npos) { + throw std::runtime_error("This software (v" + std::string(HDT_VERSION) + ".x.x) cannot open this version of HDT File (" + hdtFormat + ")"); } // Load header @@ -742,8 +743,9 @@ size_t BasicHDT::loadMMap(unsigned char *ptr, unsigned char *ptrMax, ProgressLis // Load Global ControlInformation count+=controlInformation.load(&ptr[count], ptrMax); std::string hdtFormat = controlInformation.getFormat(); - if(hdtFormat!=HDTVocabulary::HDT_CONTAINER) { - throw std::runtime_error("This software cannot open this version of HDT File (" + hdtFormat + " =/= " + HDTVocabulary::HDT_CONTAINER + ")"); + //if(hdtFormat!=HDTVocabulary::HDT_CONTAINER) { + if (hdtFormat.find(HDTVocabulary::HDT_CONTAINER_BASE) == std::string::npos) { + throw std::runtime_error("This software (v" + std::string(HDT_VERSION) + ".x.x) cannot open this version of HDT File (" + hdtFormat + ")"); } // Load Header diff --git a/hdt-lib/tools/hdt2rdf.cpp b/hdt-lib/tools/hdt2rdf.cpp index ffc7f2a3..7da86828 100644 --- a/hdt-lib/tools/hdt2rdf.cpp +++ b/hdt-lib/tools/hdt2rdf.cpp @@ -62,7 +62,7 @@ int main(int argc, char **argv) { cout << "Format: " << rdfFormat << endl; break; case 'V': - cout << "v" << HDT_VERSION << "." << INDEX_VERSION << "." << RELEASE_VERSION << endl; + cout << HDTVersion::get_version_string(".") << endl; return 0; default: cout << "ERROR: Unknown option" << endl; diff --git a/hdt-lib/tools/hdtInfo.cpp b/hdt-lib/tools/hdtInfo.cpp index 2c56386c..de40449a 100644 --- a/hdt-lib/tools/hdtInfo.cpp +++ b/hdt-lib/tools/hdtInfo.cpp @@ -68,7 +68,7 @@ int main(int argc, char **argv) { outputFile = optarg; break; case 'V': - cout << "v" << HDT_VERSION << "." << INDEX_VERSION << "." << RELEASE_VERSION << endl; + cout << HDTVersion::get_version_string(".") << endl; return 0; default: cout << "ERROR: Unknown option" << endl; diff --git a/hdt-lib/tools/hdtSearch.cpp b/hdt-lib/tools/hdtSearch.cpp index ffc73b47..049e8f84 100644 --- a/hdt-lib/tools/hdtSearch.cpp +++ b/hdt-lib/tools/hdtSearch.cpp @@ -126,7 +126,7 @@ int main(int argc, char **argv) { measure = true; break; case 'V': - cout << "v" << HDT_VERSION << "." << INDEX_VERSION << "." << RELEASE_VERSION << endl; + cout << HDTVersion::get_version_string(".") << endl; return 0; default: cout << "ERROR: Unknown option" << endl; diff --git a/hdt-lib/tools/rdf2hdt.cpp b/hdt-lib/tools/rdf2hdt.cpp index 997655e5..7bf7992c 100644 --- a/hdt-lib/tools/rdf2hdt.cpp +++ b/hdt-lib/tools/rdf2hdt.cpp @@ -93,7 +93,7 @@ int main(int argc, char **argv) { generateIndex=true; break; case 'V': - cout << "v" << HDT_VERSION << "." << INDEX_VERSION << "." << RELEASE_VERSION << endl; + cout << HDTVersion::get_version_string(".") << endl; return 0; default: cout << "ERROR: Unknown option" << endl;