Boost logo

Boost Users :

Subject: [Boost-users] [serialization] serialize type-erasure
From: oswin krause (oswin.krause_at_[hidden])
Date: 2014-09-30 05:55:22


Hi list,

i am currently trying to serialize a type-erasure, but i am not sure how
this should be done exactly. Before boost 1.56 we used the polymorphic
archives and a base class to implement serialization, but since they are
broken in 1.56 and a few users are nagging me (plus i can't compile the
library myself any more after a mandatory upgrade...), i have to get it
right.

my setup looks like this

class ErasureBase{
     ....
};

template<class T>
class Erasure{
public:
     Erasure (T& foo):m_foo(foo){}
     template<class Archive>
     void serialize(Archive & ar, const unsigned int){
         ar & m_foo;
     }
private:
     T& m_foo;
};

class MyClass{
public:
     template<class T>
     MyClass(T& foo):m_wrapper(new Erasure<T>(foo)){}
     template<class Archive>
     void serialize(Archive & ar, const unsigned int){
         ar & *m_wrapper;
     }
private:
     boost::scoped_ptr<ErasureBase> m_wrapper;

};

in the usage of MyClass i assume that serialisation/deserialisation is
only to be called on constructed objects of type MyClass, therefore i do
not need capabilities to deserialize from pointers. The question is: how
do I tell the archive which Erasure<T> exist? The solutions in the
tutorial pages only look at the cases where Erasure<T> is serialized
directly or where it is known which classes are to be serialized (and i
don't assume my users to know which Erasure<T> are instantiated...).

If there exists a solution for this: is the solution also stable wrt the
order of registration of classes?

Best,
Oswin

The ques


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