Boost logo

Boost Users :

From: Ivan Gonzalez (iglpdc_at_[hidden])
Date: 2008-06-20 18:48:46

Dear all,

I'm using the serialization library to serialize some classes to a binary
archive. These classes are basically arrays of some numerical type. As an
example say they are doubles. Later I would like to read one of these binary
archives into the same structure but using another numerical type, to which you
could promote the first one. Say for example std::complex<double>. If I was
using a simply a text file, I could read the double, without caring about its
original type, into the new type because it will be automatically promoted. You
can not do this with the binary file.

So my question is, is there any way to extract information about the class
stored in the binary archive, in this case the numerical type of the array?

I thought in using the version number of the class to label the original type,
is this the only way?

In coding:

template<class T>
struct SimpleClass{

    typedef T num_type;
    num_type data_;

    template<class Archive>
        void serialize(Archive ar, const unsigned int version)
        ar & data_;

Now given a binary archive containing a instance of SimpleClass<double>, how to
read it to an instance of SimpleClass<std::complex<double> > ? If I could get
directly from the file the type SimpleClass::num_type then I could write a
constructor in the SimpleClass to promote one to the other.

Thanks in advance.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at