|
Boost : |
From: martin.ecker_at_[hidden]
Date: 2004-05-13 05:55:29
Hello,
I was wondering what the best way would be to extend the serialization
library to allow storing state in e.g. the archive objects during the
serialization process. We could use such a facility in our project for
various purposes. For example, it would be possible to influence the
serialization of certain classes, i.e. make them write out only their
internal state but not any pointers or references to other objects, or
something like that.
Another use case for having state variables in archives: We're using
another library in our project that has its own serialization system.
So instead of writing boost::serialization code for the classes of
this library we want to use its serialization system. This is
straightforward enough by having the library serialize into a memory
buffer which is then written out using boost::serialization's
binary_object. However, we also need to do proper tracking of pointers
for that library, so we can't just create a new memory buffer every
time we encounter a pointer to one of its objects during
serialization. Therefore it would be convenient to store an "archive"
object of the library's serialization system (which calls an archive a
"stream") in the boost::serialization archive and simply write all
objects of the library we encounter to it. The library's serialization
system will track all these objects for us in a similar way
boost::serialization does. Then at the end of the serialization
process we write the additional serialization data out to the archive
using a binary_object.
In general, there are a lot of use cases I can think of where having
state variables in an archive is useful (setting flags to influence
the serialization process, deserializing smart pointers, registering
objects upon deserialization in some kind of object registry, etc.).
One way of achieving all this would, of course, be to derive from one of
the existing archive classes and add the required functionality.
However, we don't want to lose the flexibility of being able to write
out data to a binary, text, XML, or any other archive with some other
kind of representation. So basically we're looking for a good way of
inserting an additional layer in between the archives and the actual
serialize functions that can store state variables.
Thanks for any comments.
Best Regards,
Martin Ecker
TAB Austria
Industrie- und Unterhaltungselektronik GmbH & CoKG
http://www.tab.at
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk