Boost logo

Boost Users :

From: RIVASSEAU Jean Noel (JN.RIVASSEAU_at_[hidden])
Date: 2006-02-28 05:17:09


Hello,

CommonSerialize.h - remove the following

#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>

and add the following:

#include <boost/serialization/export.hpp>

test_independent.cc - change the top to look like the following:

// INDEPENDENT TEST

#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>

#include <MObject.h>
#include <MObject_serialization.hh>
#include <MemberVariableSpecification.h>
#include <MemberVariableSpecification_serialization.hh>
#include <fstream>

This won't work. Since you now have the archive headers in only one place, there is no multiple definition problem. However serialization code is *not* instantiated for MObject or MemberVariableSpecification. This is normal since when compiling the .cc that contains this code, there is no archive header included and so the export.hpp has no effect. The code is here but is not instantiated.

So in order to follow this advice:

a) include all boost/serialization/.. headers in each class file.
b) include NO boost/archive/... headers in any class file
c) make a "template instantiation module" which instanticiates code for all archives I plan to use. This can be either in the app or in a library.
d) lihk and execute without problem.

I have to explicitly instantiate the serialization code for the needed archive in the .cc files. That is, do:

template void save<boost::archive::xml_oarchive>(
    boost::archive::text_oarchive & ar, const MObject & m,
    const unsigned int file_version
);

And same for load. This is what you do in demo_pimpl.cpp. Is that what you usually do and recommend to do?

This has the advantage to avoid big compilations (these code instantiations will only occur when the class to serialize has indeed changed).

However this has the inconvenience of manually instantiating every template (and if you want to change your archive format , eg from text to xml for example, everything needs to be changed).

Jean-Noël


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