[serialization] register_type order dependent?

Is it expected that the calls to register_type need to be identical on both the save and load side of a serialization exchange? I thought I read that the registration facility sets up a map. But the following caused a archive_exception. struct C {}; struct B : C {}; struct A : B {}; --- save boost::archive::text_oarchive oa(some_ostream); oa.register_type(static_cast<A*>(0)); oa.register_type(static_cast<B*>(0)); oa.register_type(static_cast<C*>(0)); oa & aC_ptr; --- load boost::archive::text_iarchive ia(some_istream); ia.register_type(static_cast<B*>(0)); ia.register_type(static_cast<A*>(0)); ia.register_type(static_cast<C*>(0)); oa & aC_ptr; Thanks, Jeff

-> [boost-users] Zitat von Jeff Flinn <TriumphSprint2000@hotmail.com>:
Is it expected that the calls to register_type need to be identical on both the save and load side of a serialization exchange?
yes it is. register_type writes class info to your archive, which has to be read in the same order.
oa.register_type(static_cast<A*>(0));
oa.register_type<A>(); -Stefan

Stefan Strasser wrote:
-> [boost-users]
Zitat von Jeff Flinn <TriumphSprint2000@hotmail.com>:
Is it expected that the calls to register_type need to be identical on both the save and load side of a serialization exchange?
yes it is. register_type writes class info to your archive, which has to be read in the same order.
If the archive contains the registration info, are the registration calls on the load side redundant/not needed?
oa.register_type(static_cast<A*>(0));
oa.register_type<A>();
Ahh, thanks for the cleaner syntax. Thanks, Jeff

Jeff Flinn wrote:
Is it expected that the calls to register_type need to be identical on both the save and load side of a serialization exchange?
It is required.
I thought I read that the registration facility sets up a map.
It does. But the mapping has to be loaded in the order it was created
But the following caused a archive_exception.
struct C {}; struct B : C {}; struct A : B {};
--- save
boost::archive::text_oarchive oa(some_ostream);
oa.register_type(static_cast<A*>(0)); oa.register_type(static_cast<B*>(0)); oa.register_type(static_cast<C*>(0));
oa & aC_ptr;
--- load
boost::archive::text_iarchive ia(some_istream);
ia.register_type(static_cast<B*>(0)); ia.register_type(static_cast<A*>(0)); ia.register_type(static_cast<C*>(0));
oa & aC_ptr;
Thanks, Jeff
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Jeff Flinn
-
Robert Ramey
-
Stefan Strasser