[Serialization] Is there a way to "stop" a polymorphic serialization at a given class level

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.

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
participants (2)
-
nico
-
Robert Ramey