Boost logo

Boost :

Subject: [boost] [serialization] how to retreive true_type from an archive ?
From: nico (nicolas.guillot_at_[hidden])
Date: 2012-10-29 17:51:20


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).
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.

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?

Tanks for any help.

Nicolas.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk