Boost logo

Boost :

Subject: Re: [boost] [serialization] how to retreive true_type from an archive ?
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-10-29 19:58:09


nico wrote:
> Hello.
>
> Context:
> -------
> I use the boost serialization library to save and load objects of a
> system.
> I defined practices around this lib, and so I always serialize from a
> base class (every class serializable inherits from ISerializable).

I don't see that this practice is necessary. I'm not sure it's desirable
either. The serialization library goes to great lengths to make this
unnecessary. Having said that, I don't know that there's anything
wrong with it. It's off topic - but just thought I'd mention it.

> As a consequence, the true_type (i.e. the most derived type) is
> different from the this_type (i.e. ISerializable) and the true_type
> is stored in the archives.

correct.

> My question:
> -----------
> How to retreive this true_type (as the string written in the
> archive), only from the archive object?
>
> I developp just a little bit:
> ----------------------------
> Let's have this class tre:
>
> ISerializable <|-- B <|-- D
>
> If I do :
> B* b = new D();
> b->SaveToFile(path); // <= this will do the serialization ar & this
> (this being a ISerializable*)
>
> I obtain an archive where it is written the true_type "D" (whatever
> the
> type of the archive : txt, bin or xml).
>
> With the b object and this code :
> const boost::serialization::extended_type_info & true_type
> = *
> boost::serialization::type_info_implementation<ISerializable>::type
> ::get_const_instance().get_derived_extended_type_info(*b);
>
> I have what I want in true_type.get_key(), i.e : "D".
>
> I can verify that "D" is written in every archive storing b.

> My question again : how, only with an archive object (construct from
> the archive file without error), car I retrieve this key?

I think I understand the question - maybe. As the library is written,
the inquiry into the the type of object is part of the loading process
and off hand I don't see how one could "look ahead" without
actually loading the object.

You might be able to write some code which would "look ahead"
but I have no idea what it would entail.

why do you want to do this? What is the context?

Robert Ramey

>
> Tanks for any 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