Deserialization traits class

#include <x/deserialize.H>

class Aobj : virtual public x::obj {

  // ...


class Bobj : virtual public x::obj {

  // ...


class mytraits {


    template<typename ref_type>
    static void classcreate(ref_type &ref)
        if (ref.null())

std::ifstream ifs("object.dat");

std::istreambuf_iterator<char> beg(ifs.rdbuf()), end;

x::deserialize::iterator<std::istreambuf_iterator<char>, mytraits>
   deser(beg, end);

// ...

   x::ptr<Aobj> a;


An optional second parameter to the deserialization iterator template specifies a template class. When deserializing a reference to an object, the reference gets passed to the classcreate() static method of the traits class.

The above example is the default traits class, which invokes the default constructor for the object to initialize a null reference. If the reference passed to the deserialization iterator already refers to an existing object instance, it gets left alone.

The default traits class also has a specialized classcreate for deserializing file descriptors.

A custom serialization traits class can define specialized classcreate() methods for instantiating references to new class instances.