Boost logo

Boost :

Subject: Re: [boost] [serialization] non-tracking wrapper?
From: joaquin_at_[hidden]
Date: 2008-11-12 02:22:48


Robert Ramey escribió:
> when this first came up, it thought that it would be possible to do this.
> Now that I think about this, I don't see that its possible.
>

I think something to this effect can be implemented resorting to
<drumroll>helper support</drumroll>. Non-tested pseudocode follows.
The idea is not to supress tracking (which can't be done) but rather to
move stack-based
objects to a safe location so that Boost.Serialization does not get
confused by objects
with potentially the same stack address.

template<typename T>
struct non_tracking
{
  non_tracking():p(0){}
  non_tracking(const T& t):p(&t){}

  const T& get()const{return *p;}

  const T* p;

  struct helper
  {
    typedef std::list<T> table_type;
    table_type table;
  };

  template<class Archive>
  void save(Archive & ar,const unsigned int)const
  {
    helper::table_type& table=ar.get_helper<helper>().table;
    table.push_back(*p);
    ar<<table.back();
  }

  template<class Archive>
  void load(Archive & ar,const unsigned int)
  {
    helper::table_type& table=ar.get_helper<helper>().table;
    T t;
    ar>>t;
    table.push_back(t);
    ar.reset_object_address(&table.back(),&t);
    p=&table.back()
  }
};

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