Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-04-09 03:53:01

Robert Ramey wrote:
>> I've found an implementation of shared pointer serialization that
>> martin ecker sent me some time ago. It seems to me that it is
>> simple transparent and would satisfy all requirements.

Depends on whether your requirements include serializations of shared_ptr<X>
for different X'es sharing ownership.

template<class Archive, class T>
inline void load(
    Archive & ar,
    boost::shared_ptr<T> &t,
    const unsigned int /* file_version */
 T* r;
 ar >> boost::serialization::make_nvp("px", r);
 t = ar.get_shared_ptr_registry().lookup(r);

lookup(r) probably returns a shared_ptr<T> for the assignment to work...
This probably means that there are separate map< T*, shared_ptr<T> >
registries for each T.

 if (!t)

This approach covers most of the real-world cases, so it's definitely better
than the status quo. Go for it.

Boost list run by bdawes at, gregod at, cpdaniel at, john at