Boost logo

Boost :

Subject: Re: [boost] [Serialization] Is there a way to "stop" a polymorphic serialization at a given class level
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-04-16 12:59:09


nico wrote:
> 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*.
> What do you recommend ?

There should be someting in your code like:

template<class Archive>
void serialize(Archive & ar, B & b, const unsigned int version){
    ar & static_cast<A & a>(*this); //serialize base class data
   ar & m_b1 & m_b2 ...; // serialize data from class b
}

So just comment out or remove the first statement which invokes
serialization to the base class A.

Robert Ramey
>
> Thanks for help.
>
> Nicolas.
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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