From 0ac79d260102e0d2662a81c48d2d96f65ba6bf0b Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Thu, 22 Dec 2022 22:52:39 +0100 Subject: [PATCH] OMF: make version available --- modules/io/src/mol/omf.cc | 9 +++++++-- modules/io/src/mol/omf.hh | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/io/src/mol/omf.cc b/modules/io/src/mol/omf.cc index 2de1e477f..bad82b3df 100644 --- a/modules/io/src/mol/omf.cc +++ b/modules/io/src/mol/omf.cc @@ -3295,7 +3295,10 @@ void OMF::ToStream(std::ostream& stream) const { uint32_t magic_number = 42; stream.write(reinterpret_cast<char*>(&magic_number), sizeof(uint32_t)); - uint32_t version = 2; + // We set it to the current version... + // If you loaded a structure from a previous version and you dump it again, + // the version will be updated. + uint32_t version = OMF_VERSION; stream.write(reinterpret_cast<char*>(&version), sizeof(uint32_t)); stream.write(reinterpret_cast<const char*>(&options_), sizeof(uint8_t)); @@ -3335,7 +3338,9 @@ void OMF::FromStream(std::istream& stream) { throw ost::Error(ss.str()); } - if(version > 1) { + version_ = version; + + if(version_ > 1) { stream.read(reinterpret_cast<char*>(&options_), sizeof(uint8_t)); } diff --git a/modules/io/src/mol/omf.hh b/modules/io/src/mol/omf.hh index a1756bf61..dc9dfc131 100644 --- a/modules/io/src/mol/omf.hh +++ b/modules/io/src/mol/omf.hh @@ -30,6 +30,8 @@ namespace ost { namespace io { +const int OMF_VERSION = 2; + class ChainData; class BioUnitData; class OMF; @@ -181,6 +183,10 @@ public: ost::mol::EntityHandle GetBU(int bu_idx) const; + int GetVersion() const { return version_; } + + static int GetCurrentOMFVersion() { return OMF_VERSION; } + private: // only construct with static functions OMF(): options_(0) { } @@ -208,6 +214,8 @@ private: // bitfield with options uint8_t options_; + + int version_; }; }} //ns -- GitLab