I want to serialize a class I don’t have write access to. I.e., I can’t change the source file nor the header file. Furthermore, most fields are private and are accessed through getter and setter functions.
Can anyone tell me whether it is a good idea (or not) to just create different functions for saving and loading (as explained in the boost tutorial)…
template<class Archive>
void save(Archive & ar, gps_position &g, const unsigned int version) const
{
// note, version is always the latest when saving
ar & g.deg;
ar & g.min;
}
template<class Archive>
void load(Archive & ar, gps_position &g, const unsigned int version)
{
if(version > 0)
ar & g.deg;
ar & g.min;
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
… and there use the public functions:
ar & g.getDeg();
instead of
ar & g.deg;
(similar for setter)?? I’m really new into c++ and serialization and I’m very thankful for any hints!
best, alex
edit: added link to boost tutorial
something like this. declare variable -> read from archive -> set to member by calling setter function.