|
Boost Users : |
Subject: [Boost-users] [serialization] customizing save/load for a type (pointer)
From: Mathieu Champlon (m.champlon_at_[hidden])
Date: 2013-10-17 01:28:27
Hi,
I'm using Boost.Serialization on a project where part of the data is not
serialized and then loaded separately when unserializing.
For instance a class MyThing can have a member data MyThingData* which
described some "static" data.
There is an application which edits these data and saves them on file
for the main application to use latter on.
When serializing MyThing we customize save/load in order to serialize
MyThingData as a UID (MyThingData has a GetId member function).
Upon unserialization the proper MyThingData instance is searched for
based on the UID read from the archive.
This works OK but is a bit tedious because with
class MyThing
{
...
MyThingData* data_;
};
instead of simply doing
template< typename Archive > void serialize( Archive& ar, const
unsigned int )
{
ar & data_;
}
we have to do something like
BOOST_SERIALIZATION_SPLIT_MEMBER()
template< typename Archive > void load( Archive& ar, const unsigned
int )
{
int id;
ar >> id;
data_ = FindData( id ); // not very important how it is
actually retrieved
}
template< typename Archive > void save( Archive& ar, const unsigned
int ) const
{
ar << data_->GetId();
}
Moreover things get even more complicated when serializing for instance
a std::vector< MyThingData* > ...
So I'm looking for a way to customize the serialization of MyThingData*.
Of course I could wrap MyThingData* in a simple object to encapsulate
save/load but they're everywhere and the code base is quite massive so
this would require a lot of changes.
Any idea how I could achieve this ?
Thank you !
Regards,
MAT.
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