Boost logo

Boost Users :

Subject: [Boost-users] [serialization] can I serialize concrete types that are not acessible where the archive is created
From: Massaro Alessio (Alessio.Massaro_at_[hidden])
Date: 2010-09-28 13:58:35


Hi there!

Does boost::serialization work with interfaces and static factory methods?
(shown below)

Note how the Concrete type is not actually known at the point where the
archive is instantiated, and the two are actually in two different
modules. In fact, I have indeed tried the following line in ConcreteType.cpp
but the registration is not seen by the text_oarchive in DLL 2

BOOST_CLASS_EXPORT_GUID(ConcreteType, "ConcreteType")

Perhaps using a singleton archive on which I register every type (from
Multiple DLLs) and that I use to serialize every object?
But how would I provide access to register_type on such a singleton?
And how would I use it on different stream instances? (a clone?)

I m trawling through the boost::serialization code, and cannot find a way to
make it work.

Thanks in advance for any pointers/help!

##################### DLL/MODULE 1 #####################################

### interface.hpp

struct DLL_EXPORT I_DoSomething
{
        void doIt() = 0;
        static I_DoSomething* create(); // static factory
}

### ConcreteType.cpp

#include "interface.hpp"

class ConcreteType : public I_DoSomething { ... }

I_DoSomething* create() { return new ConcreteType(); }

##################### DLL 2 which linked with DLL 1 #####################

### serialize.cpp

#include "interface.hpp"
#include <boost/archive/text_oarchive.hpp>

...
I_DoSomething* obj = I_DoSomething::create();

boost::text_oarchive oa;
oa << obj;
...


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