[serialization] Cannot increase version of stored objects

I need to update the version certain objects in my structure, but I cannot get the version number incremented. Scenario: I have a class MyClass which have several entries of InternalClass objects (which is the one I want a new version of): class MyClass { ... template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION("MyInternals", m_vector_of_internal_class_objects); } std::vector<InternalClass> m_vector_of_internal_class_objects; class InternalClass { template<class Archive> void save(Archive & ar, const unsigned int version) const { ar & BOOST_SERIALIZATION("data", m_data); } template<class Archive> void load(Archive & ar, const unsigned int version) { if (version == 0) { old_data_t tmp; ar & BOOST_SERIALIZATION("data", tmp); m_data = convertToNewData(tmp); } else { BOOST_CHECK(version == 1); ar & BOOST_SERIALIZATION("data", m_data); } } BOOST_SERIALIZATION_SPLIT_MEMBER() new_data_t m_data; } } Then in the body (.cpp) I define: BOOST_CLASS_VERSION(MyClass::InternalClass, boost::serialization::object_class_info) BOOST_CLASS_VERSION(MyClass::InternalClass, 1) But when saving to the XML archive file, I still get version="0" for the InternalClass objects (?) /R

Try putting it in the header (*.hpp) which contains the class delaration Robert Ramey Robert Bielik wrote:
Then in the body (.cpp) I define:
BOOST_CLASS_VERSION(MyClass::InternalClass, boost::serialization::object_class_info) BOOST_CLASS_VERSION(MyClass::InternalClass, 1)
But when saving to the XML archive file, I still get version="0" for the InternalClass objects (?)
/R

I have a structure like: class A { int m_position; int m_value; template<class Archive> void save(Archive & ar, const unsigned int version) const { ar & BOOST_SERIALIZATION("pos", m_position); B* b = somehow_get_hold_of_my_object_of_class_B; int temp = b->convertToSerializedFormat(m_value); ar & BOOST_SERIALIZATION("value", temp); } template<class Archive> void load(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION("pos", m_position); B* b = somehow_get_hold_of_my_object_of_class_B; int temp; ar & BOOST_SERIALIZATION("value", temp); m_value = b->convertFromSerializedFormat(temp); } } class B { std::vector<A> m_vector; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & BOOST_SERIALIZATION("posvalues", m_vector); } int convertToSerializedFormat(int value); int convertFromSerializedFormat(int value); } I could have a B* pointer in each of my A objects, but cannot afford that due to tough memory constraints. So the issue is how to get hold of a B* pointer (which is the object that holds the vector of A objects) ?? TIA /R
participants (2)
-
Robert Bielik
-
Robert Ramey