Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] Serialize base and derived classes.
From: BlueAngel (lists_at_[hidden])
Date: 2010-07-26 12:58:39


Hi lists,
I'm working with the Serialization library but I'm having some troubles
with it.
The tutorials in the website shown me much but still I need help.

I'm using XML archives.
I have this classes actually (these classes are all builders/prototypes,
they serialize the datas and then they should make a new object with
those datas):
Serializer (an interface, every class which need serialization must be
derived from this, however this is only a marker, it will be not serialized)
RenderableSerializer : public Serializer - this isn't pure virtual
however shouldn't be never serialized directly (since the object made by
this class is a pure virtual one) - These will use the tag <renderable>
SkyboxSerializer : public RenderableSerializer - these will use the tag
<skybox>
EntitySerializer : public Serializer - these will use the tag <entity>
many other classes will be added in future and they'll all derive form
RenderableSerializer.

Now the problem is EntitySerializer have a pointer to a
RenderableSerializer and when I serialize EntitySerializer the pointer
to that class is considered to be a RenderableSerializer and not the
derived class. I don't know at priori which class is the base class and
this lead to problem.
If I serialize a SkyboxSerializer I have the correct tag: a <skybox>
which have inside a <renderable> and the datas are correct.
If I try to serialize an Entity I had a lot of problem, mostly just make
the library crash. As I've seen in the tutorial I should register all
the derived classes before pass the pointer to the Archive. I did it
registering the SkyboxSerializer classes but it lead to a wrong xml: a
correct <entity> tag which have a correct <skybox> with all it's data
but also a wrong <renderable> tag which have inside the same data of the
tag <skybox> instead of the data of a RenderableSerializer class.

Now the question is: is there a correct way to use the library this way?
With a pointer to a base class of which the derived is not known?
My code is too big and I made many attempt to use the library so I'm not
posting it in this message. If you need it I will post it.
Thank you for your replies.



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