
Preston A. Elder wrote:
It would seem to me that the easiest way to do this would be to make a TEE type streambuf using the stream buffer library. This would duplicate each write to an additional stream. Do you mean with boost::iostream? or as a part of boost::serialization?
Remember that serialization uses streambuf for doing the actual i/o. Hence any thing that streambuf (boost streams) implements such as compression, duplicaiton, etc, is "inherited" by boost serialization.
however the biggest barrier to this is the fact that serialization does not allow me to put the same object into the stream twice. To be more precise, I want to be able to serialize both to a network and to disk, and I very much like the elegance of the serialization approach (plus the fact it can re-create pointer references, arrays, and such).
I believe the above would cover this. TEE would handle going to both network and disk, but it would not obviate the 'single object only once' problem. According to the serialization documentation (Reference -> Speical Considerations -> Object Tracking
This would be done by setting the serialization trait "tracking" to track_never. This would inhibit the checking for duplicates. This would occur before it gets to the stream buf implementation
(http://www.boost.org/libs/serialization/doc/special.html#objecttracking)), an object may only be put on the stream once, I cannot put an object that has been changed on the stream again to be re-serialized (either by replacing the previously serialized entry, or adding it to be serialized again, but without allocating a new object).
that's what "track_never" is for.
This is why I was asking in the first place how difficult the modifications would be to allow an object to be serialized twice, and serialization to understand this and not create a separate instance, but just update the existing instance.
So track_never permits the object to be written multiple times. Using a custom streambuf would place the serialized output into multiple streams. Robert Ramey