
Hi, By design Boost Serialization requires the user to list each field that needs to be serialised. This is in contrast, for example, with Java and some other languages where serialisation is supported (kind of) at the language level. The current approach requires some code duplication. We have to declare a field. We have to manually (de)serialise it. If we need to make a change, we make it in at least two distinct places. Is there any way to automate the process of serialisation, perhaps harnessing the power of the preprocessor? E.g. we could label the fields that need to be serialised. Is there anything in Boost that could help? Many thanks, Paul Paul Bilokon, Vice President Citigroup | FX - Options Trading | Quants 33 Canada Square | Canary Wharf | Floor 3 London, E14 5LB Phone: +44 20 798-62191 paul.bilokon@citi.commailto:paul.bilokon@citi.com

Am Thursday 26 November 2009 14:05:18 schrieb Bilokon, Paul:
Hi,
By design Boost Serialization requires the user to list each field that needs to be serialised.
This is in contrast, for example, with Java and some other languages where serialisation is supported (kind of) at the language level.
The current approach requires some code duplication. We have to declare a field. We have to manually (de)serialise it. If we need to make a change, we make it in at least two distinct places.
Is there any way to automate the process of serialisation, perhaps harnessing the power of the preprocessor? E.g. we could label the fields that need to be serialised. Is there anything in Boost that could help?
not that I'm aware of, but I even think that's a good thing. the serialize() function represents a file format, and you want file formats to be stable and not being changed because someone added a runtime field to a class. usually when you do want to add a serialized field you'd also want old versions of the file still to be readable, so you end up writing custom (versioned) deserialization code anyway, even if your language has built-in serialization support. you could use some compile time code generator to write default serialization code for you, using e.g. OpenC++, GCC-XML, or Doxygen, but I doubt those generated functions would stay there very long.

On Thu, Nov 26, 2009 at 5:05 AM, Bilokon, Paul
Hi,
By design Boost Serialization requires the user to list each field that needs to be serialised.
This is in contrast, for example, with Java and some other languages where serialisation is supported (kind of) at the language level.
No, Paul, C++ has no reflection and the reason is that unlike Java it does not define ABI. Consider that in C++ not only the size of the built-in types is not standardized, but even some operations have "implementation-defined" semantics.
The current approach requires some code duplication. We have to declare a field. We have to manually (de)serialise it. If we need to make a change, we make it in at least two distinct places.
You are thinking in terms of reflection. Think in terms of states and invariants and it'll make more sense. For example, if you have an array of items and a pointer, and your invariant is that the pointer always points the last element in the array, the pointer should not be serialized. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (3)
-
Bilokon, Paul
-
Emil Dotchevski
-
Stefan Strasser