|
Boost Users : |
From: Bill Lear (rael_at_[hidden])
Date: 2006-06-15 08:53:00
On Thursday, June 15, 2006 at 09:56:00 (+0100) Russell Hind writes:
>...
>One object type in the archive we written at version 1 by a newer
>version of the application. We then ran an older version of the
>software which only understood version 0 of the object.
>
>Does serialization not check the 'BOOST_CLASS_VERSION' of an object
>before attempting to de-serialize it?
I think what you mean is: does boost serialization guard against
forward incompatibility? It does not: that's your job. For any version
of your code, if you want to guard against forward incompatibility,
you simply need to do this:
#define TEST_CURRENT_VERSION 3 // or, something more sophisticated ..
class test {
template <typename Archive>
void serialize(Archive& ar, const unsigned int version) {
// This code will refuse to try to load serialized archives >= 4
if (version > CURRENT_VERSION) {
throw forward_incompatibility_error("...");
}
}
};
BOOST_CLASS_VERSION(test, TEST_CURRENT_VERSION);
Of course, you could make an argument that boost should do this
automatically.:-)
Bill
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net