Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2007-10-08 19:34:01


Hi Jeremy,

----- Mensaje original -----
De: Jeremy Maitin-Shepard <jbms_at_[hidden]>
Fecha: Lunes, Octubre 8, 2007 10:15 pm
Asunto: Re: [boost] [serialization] Proposal for an extension API to
theArchive concept
Para: boost_at_[hidden]

> I think there is a significant issue with your proposed extension
> mechanism: an archive can only contain a single extension object
> at a time. Consequently, if two types require different extension
> objects, they cannot both be serialized using the same archive.
> In particular, if say flyweight requires some special extension
object,
> and shared_ptr requires its own special extension object, it won't
be
> possible to serialize both using the same archive. It seems,
therefore,
> that in practice there would have to be a single standardized
extension
> object,which is either in use or not in use for a particular archive.

My proposal allows for any type to register and use its own
helper object: note that the proposed extension interface:

  a.get_extension_obj(p);
  a.set_extension_obj(p);

is *not* meant to be public; quoting from http://tinyurl.com/2tuucq :
"These expressions are reserved for the internal usage of
Boost.Serialization and thus must not be called by user code."
It is then Boost.Serialization that adjoins its own extension
object to an Archive and publicizes a helper API based upon
this internal object:

  template<typename Archive>
  void insert_helper(
    Archive& ar,
    const extended_type_info* eti,
    shared_ptr<void> & sph)
  {
    // get the extension object or create a new one if this
    // is the first time

    shared_ptr<void> ext_obj=ar.get_extension_obj();
    if(!ext_obj){
      ext_obj.reset(new extension);
      ar.set_extension_obj(ext_obj);
    }
    extension& ext=*ext_obj;

    // forward to the extension object
    ext.insert_helper(eti,sph);
  }

So, each distinct T can register its separate helper
object more or less like this:

  serialization::extended_type_info* eti=
    serialization::type_info_implementation<helper<T> >::
    type::get_instance();
  shared_ptr<void> sph;
  insert_helper(ar,eti,sph);
  ...

Did I make myself clearer now?

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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