From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-04-08 12:53:51


Robert Ramey wrote:
> Peter Dimov wrote:
>> The author of boost::shared_ptr wants to, but it isn't
>> straightforward and will take time; and you aren't helping me much, I
>> might add.
>
> Hmmm I understood that you didn't want to include serialization
> inside the implementation of shared_ptr but had insisted on and
> totally non-intrusive one which depended only on public interface of
> shared_ptr. That's what I was refering to.

Yes, I still want to use only the public interface of shared_ptr in its
serialization. This will allow people to use the same serialization
algorithm with tr1::shared_ptr.

>> Your other suggestion was "add a serialize member to shared_ptr and
>> just make it work." This is easier said than done. The serialization
>> library is fairly complex and figuring out the best way to extend it
>> non-intrusively with the necessary support requires more time than I
>> have at the moment.
>
> Welcome to the club.

Good point.

(apologies for quoting out of order)

> I never failed to see your point - I just never really saw an
> attractive resolution. Lacking such a resolution - I've "made it
> work" which is more than anyone else has done.

I've attached my current draft version. The top part is the shared_ptr
serialization support, the rest (after namespace boost is closed) is a
simple test.

It uses the ordinary BOOST_CLASS_EXPORT_GUID mechanism for class
registration, but serialization via a base class requires an additional
step:

    register_conversion<base, derived>();

at the top of main.cpp.

The main thing that makes this a draft and not a production version are the
two global std::map objects at the top, sp_save_map and sp_load_map.

These need to be injected into the archive.

The register_conversion step cannot be eliminated without adding specific
shared_ptr support to the serialization library; its void_cast mechanism
cannot be used to upcast a shared_ptr to shared_ptr.

When I wrote the code I intended to provide a mechanism to inject the
pointer maps into the archive types via inheritance. Then I ran out of time.

So, basically, the only thing that remains to be done is a mechanism to
inject sp_load_map into an iarchive, and sp_save_map into an oarchive. If
you have (or anyone else has) an easy solution to this problem, that would
be great.