boost::serialization - prevent object creation when loading a pointer
Peter Dimov wrote:
You can add
virtual void load( boost::archive::text_iarchive& ar, unsigned v ) = 0; virtual void save( boost::archive::text_oarchive& ar, unsigned v ) = 0;
to base and call them in A::serialize, but this obviously only works for a specific archive type.
I specifically need to be able to support different archives, so this won't work - but I think something similar to what you have suggested will. Robert Ramey wrote:
How about the following:
template<class Archive> void save(Archive& ar, const unsigned int version) const { ar << _m; cout << "serialise A, _m = " << (unsigned long)_m << endl;}
void save(Archive& ar, const unsigned int version) const { base * t; ar >> t; // deserialize to a temporary // modify _m according to t cout << "serialise A, _m = " << (unsigned long)_m << endl; delete t;
}
Yeh something like this would do the trick.
So actually, what I am thinking of is a kind of a mix of Robert's and
Peter's suggestions (see code below). It is not the prettiest, but I
think I should only have to do this for one class hierarchy in
particular, so it isn't too bad.
Thanks for your help. The serialization library is going to make my life
a lot easier!
Darryl Lawson
#include <iostream>
#include <fstream>
#include <cassert>
#include
participants (1)
-
Darryl Lawson