Re:[boost] [serialization] documentation for xml archive usage

However, this triggers a BOOST_STATIC_ASSERT in basic_xml_oarchive<Archive>::save_override<T>(const T&, BOOST_PFTO int).
The implementation insists that all serialized types be wrapped in a nvp<T>.
That is the intent.
But I couldn't find an explanation in the docs what special steps a user is supposed to take if the data shall be serialized into an xml archive. (The only hint that xml archives need special care that I found was the description of the header file nvp.hpp libs/serialization/doc/headers.html: "To associate a name tag with a serializable object. This is necessary to properly render an xml archive which includes the object name." BTW, this webpage claims nvp.hpp is in boost/archive, but in fact it is in boost/serialization.)
Do I need to write
ar & nvp<MyMemberType>("my_member_tag", this->my_member);
in my serialization functions for every variable I want to (de-)serialize? Can I choose an arbitrary tag for each variable or is it supposed to be consistent for all variables of a specific type?
Oh - no. Use the variable name for the tag not the name of the type. This is encouraged by usage of the idiom ar & BOOST_SERIALIZATION_NVP(my_variable);
Am I correct to assume that the code will still work if I serialize into a "normal" text archive and the nvp will essentially be ignored?
And all other archives as well - with no extra runtime overhead (assuming a decent optimizing compiler) There a section Reference:Class Serialization:Serialization Wrappers:Name-Value pairs where this is described. Perhaps this isn't obvious from contents.
May I suggest that a section explaining the issues with xml archives be added to the docs before the 1.32 release?
Yes you may.

On Mon, Sep 27, 2004 at 09:58:04AM -0700, Robert Ramey wrote:
However, this triggers a BOOST_STATIC_ASSERT in basic_xml_oarchive<Archive>::save_override<T>(const T&, BOOST_PFTO int).
The implementation insists that all serialized types be wrapped in a nvp<T>.
That is the intent.
[...]
There a section Reference:Class Serialization:Serialization Wrappers:Name-Value pairs where this is described. Perhaps this isn't obvious from contents.
After I saw Vladimir's post I found it. This section describes everything I needed to know, thank you.
May I suggest that a section explaining the issues with xml archives be added to the docs before the 1.32 release?
Yes you may.
I don't know if I represent an average user or whether I simply was too dumb to use the docs... :-) But if you consider using the xml archive then you look in the documentation for "xml"; it's not obvious that you should rather look for "Name-Value pairs". Perhaps a patch similar to the one I am going to attach can remedy this problem? Regards Christoph PS: According to headers.html#userincludes, nvp.hpp is in boost/archive. But it is in fact in boost/serialization. -- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html

On Mon, 27 Sep 2004 09:58:04 -0700, Robert Ramey <ramey@rrsd.com> wrote:
Oh - no. Use the variable name for the tag not the name of the type. This is encouraged by usage of the idiom
ar & BOOST_SERIALIZATION_NVP(my_variable);
Might I also suggest a similar interface which allows the caller to specify the name to go with the value: BOOST_SERIALIZATION_NAME_VALUE ("variable", m_variable); I'm sure many folks add prefix m_ or trailing underscore warts to member names, and IMHO these don't really have any business being in the serialized form of the object. -- Caleb Epstein caleb.epstein@gmail.com

"Caleb Epstein" <caleb.epstein@gmail.com> wrote in message news:989aceac04092808315b0da3e3@mail.gmail.com...
On Mon, 27 Sep 2004 09:58:04 -0700, Robert Ramey <ramey@rrsd.com> wrote:
Oh - no. Use the variable name for the tag not the name of the type. This is encouraged by usage of the idiom
ar & BOOST_SERIALIZATION_NVP(my_variable);
Might I also suggest a similar interface which allows the caller to specify the name to go with the value:
BOOST_SERIALIZATION_NAME_VALUE ("variable", m_variable);
I'm sure many folks add prefix m_ or trailing underscore warts to member names, and IMHO these don't really have any business being in the serialized form of the object.
In this case there's no need for a macro. Just use: using boost::serialization::make_nvp; ar & make_nvp( "variable", m_variable); What would be useful (for me ) would be a macro that used a user defined default for the prefix. We use CamelCase type names here. #define BOOST_SERIALIZATION_NVP_PREFIX_DEFAULT m ar & BOOST_SERIALIZATION_NVP_PREFIXED( Variable ); Which would be equivalent to: ar & make_nvp( "Variable", mVariable); But, looking at it now, the non-macro version is more readable, flexible and fewer characters to boot. Jeff F
participants (4)
-
Caleb Epstein
-
Christoph Ludwig
-
Jeff Flinn
-
Robert Ramey