Boost logo

Boost Users :

From: Luca Cappa (luca.cappa_at_[hidden])
Date: 2007-04-19 04:15:36


Hello,

> I took your code and fixed it up to that below and it compile and tests
> fine.
>
> Note the usage of BOOST_SERIALIZATION_BASE_OBJECT_NVP
> below which is key. This is explained in the documentation.
>

thanks a lot for the answer. Now it works correctly, I still "dare" to
give a suggestion and ask help again:

1) In the documentation I think that the relevant information about how to
serialize properly a derived polymorphic class should stay also in
"Pointers to Objects of Derived Classes -> Registration". In that section
is not mentioned boost::serialization::base_object nor
BOOST_SERIALIZATION_BASE_OBJECT_NVP, and I think it would be helpful to
add an explanation in there: in fact the provided example (class base ...
class derived_one ... derived_two) does not work out of the box.
I think that to the above mentioned section should be added a reference
(or directly the content) of the section
Serializable Concept->Pointers->Pointers of Derived Objects->Runtime
Casting, which explicitly says to call
boost::serialization::base_object<base>(*this), so that the relationship
between a "base/derived pair is added to the table", and make things
working :)

2) Since I do not like to serialize the base object, I do not want to call
boost::serialization::base_object in the derived serializing method, but
instead I wish to just explicitly register base/derived relationship with:

boost::serialization::void_cast_register<derived, base>();

as the section Runtime Casting tells the reader. But it does not work
(compilation fails), I still need to add two NULLs parameters to that
function, such as:

boost::serialization::void_cast_register<Serializable,
SerializableBase>(NULL, NULL);

so the code of derived::base::serialize method of the example should be
corrected. By the way in file void_cast_fwd.hpp for the method
void_caster::void_cast_register the default arguments to NULL appear to be
commented out, I wonder why.

3) What is preferred statement between

oa.register_type (static_cast<Serializable*> (NULL));

and

oa.register_type<Serializable> ();

?
I tested that either works fine with VC8, and I guess they work fine with
gcc4 too, but i wonder why I see in
the examples of Boost the former used in place of the latter form which is
commented out.

Best regards,
Luca Cappa


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