Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2008-02-04 12:38:22


 template<
    class Archive,
    typename T,typename Arg1,typename Arg2,typename Arg3
>
  void save(
    Archive& ar,const ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
    const unsigned int version)
  {
      typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3> flyweight;
      ar << f.get(); // use serialization tracking - no need to call
helper
  }

  template<
    class Archive,
    typename T,typename Arg1,typename Arg2,typename Arg3
>
  void load(
    Archive& ar,const ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
    const unsigned int version)
  {
    typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3> flyweight;
    T t;
    ar >> t;
    f = t; // look up here
    ar.reset_object_address(& f.get(), &t);
  }

vs.

// from flyweight serialize

template<
    class Archive,
    typename T,typename Arg1,typename Arg2,typename Arg3
>
void load(
    Archive& ar,::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3>& f,
    const unsigned int version
){
    typedef ::boost::flyweights::flyweight<T,Arg1,Arg2,Arg3> flyweight;
    typedef ::boost::flyweights::detail::serialization_helper<flyweight>
helper;
    typedef typename helper::size_type size_type;
    helper& hlp=
    ::boost::flyweights::detail::get_serialization_helper<flyweight>(ar);
    size_type n=0;
    ar>>make_nvp("item",n);
    if(n>hlp.size()){
        throw_exception(
        archive::archive_exception(archive::archive_exception::other_exception));
    }
    else if(n==hlp.size()){
        ::boost::flyweights::detail::archive_constructed<T>
v("value",ar,version);
        hlp.push_back(flyweight(v.get())); // Doesn't push_back need to do a
find?
    }
    f=hlp[n];
}

I've delved into the helper. I kind of ran out of gas at multi-index.
Doesn't this require
a lookup to maintain the mult-indexed table?. Also using the helper entails
a lot more
generated code. It looks like a bunch more code generated for each type
flyweight.
I'm not convinced that there is a real saving here.

If you dropped the helper, then you're class would be serializable right now
and it would entail a lot less code. You could always make it more
elaborate later.

Robert Ramey


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