Boost logo

Boost :

Subject: [boost] [Serialization] Is there a way to "stop" a polymorphic serialization at a given class level
From: nico (nicolas.guillot_at_[hidden])
Date: 2012-04-16 09:46:46


Hello.

I admit the subject is not really understandable, but you'll see it's not
so obvious to summarize the question...

I use the boost serialization system and its polymorphic base serialization
feature.
For that, and for serialization code instantiation, I use the registration
macros BOOST_CLASS_EXPORT_KEY and BOOST_CLASS_EXPORT_IMPLEMENT.

If I have a concrete class A in a inheritance tree like that :
C is base of B is base of A ( C <|---B <|---A )
C is not instanciable (it has pure virtual functions)
B is instanciable

Is there a way to "stop" the serialization of a A object to B level?

I mean:
If I have this code:

C* obj = new A();
// declare boost archive ar to serialize obj
ar & obj;

Is there a way to tell to boost serialization to serialize only until B.

Why ?
This obj serialized is deserialized in another application, where only C
and B are known and used.
A only defines technical stuff, but nothing with data (and serialization),
so it will never be used as A*.

I try with something like that :

template<class Archive>
void A::serialize(Archive & ar, const unsigned int version)
{
    B* b = new B(static_cast<B*>(this));
    ar & b;
    delete b;
}

but is there a more "boost-serialization-system" way ? (I expect no...)

What do you recommend ?

Thanks for help.

Nicolas.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk