Commit 83057123 authored by Davis King's avatar Davis King

Added check_serialized_version().

parent 973f4536
...@@ -171,10 +171,27 @@ namespace dlib ...@@ -171,10 +171,27 @@ namespace dlib
class serialization_error : public error class serialization_error : public error
{ {
/*!
WHAT THIS OBJECT REPRESENTS
This is the exception object. It is thrown if serialization or
deserialization fails.
!*/
public: public:
serialization_error(const std::string& e):error(e) {} serialization_error(const std::string& e):error(e) {}
}; };
void check_serialized_version(
const std::string& expected_version,
std::istream& in
);
/*!
ensures
- Deserializes a string from in and if it doesn't match expected_version we
throw serialization_error.
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T> template <typename T>
...@@ -1737,6 +1754,19 @@ namespace dlib ...@@ -1737,6 +1754,19 @@ namespace dlib
} }
} }
// ----------------------------------------------------------------------------------------
inline void check_serialized_version(const std::string& expected_version, std::istream& in)
{
std::string version;
deserialize(version, in);
if (version != expected_version)
{
throw serialization_error("Unexpected version '"+version+
"' found while deserializing object. Expected version to be '"+expected_version+"'.");
}
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment