Boost logo

Boost Users :

From: Russell Hind (rh_gmane_at_[hidden])
Date: 2006-06-15 04:56:00


We have system data written out to an XML archive and being
de-serialized at application startup.

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?

If not, how can we access the 'BOOST_CLASS_VERSION' in a serialization
member function? I'm looking to do something like this: (this code is
just written now so probably is incorrect but hopefully gives the idea).
  How do we check 'version_of_T' below which should correspond to the
BOOST_CLASS_VERSION for T?

I'd probably have this only check if the ArchiveT::is_loading::value is
true as serializing doesn't matter.

The issue at the moment is that an access violation is being thrown
which definitely isn't a good idea. I'd like a 'newer object version'
exception thrown instead which would enable us to give more useful error
information to the user or our error log.

Thanks

Russell

namespace serialization
{
   template <typename T>
   void check_version(T* Object, unsigned int version))
   {
     if (version_of_T > version)
     {
       throw newer_version_exception();
     }
   }
}

class test
{
   template <typename ArciveT>
   void serialize(ArchiveT& ar, unsigned int version)
   {
     serialization::check_version(this, version);
   }
};

BOOST_CLASS_VERSION(test, 0x00);


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