|
Boost Users : |
From: Robbie Morrison (robbie_at_[hidden])
Date: 2007-08-29 12:44:29
Hello all
Regarding the Boost.Serialization library.
Archiving to XML requires the use of name-value-pairs for all
serialized objects, be they stand-alone or encapsulated.
I wanted to confirm the following is correct.
In reference to the online and bundled HTML documentation:
http://www.boost.org/libs/serialization/doc/serialization.html#const
file:///.../boost_1_34_1/libs/serialization/doc/serialization.html#const
It would appear that the code block which reads:
ar & const_cast<T &>(t);
should also mention that, in the case of XML serialization:
using boost::serialization::make_nvp; // for convenience
ar & make_nvp("t", const_cast<T &>(t)); // cast used on load
Moreover, this code could be a candidate for a macro, something like
(or would this create its own can of worms?):
ar & BOOST_SERIALIZATION_NVP_CONSTDATA(T, t);
ar & BOOST_SERIALIZATION_CONSTDATA_NVP(T, t);
--- On that note, a new page describing user Boost.Serialization macros and their usage might be helpful. For instance I have created the following list (readers should note that my comments may well be incorrect): BOOST_CLASS_EXPORT_GUID(SubClass, "MySC") // GUID is "globally unique id" BOOST_CLASS_EXPORT(SubClass) // shortcut if class name is acceptable BOOST_CLASS_VERSION(Class, 2) // reset class version, the default is zero BOOST_IS_ABSTRACT(AbstractClass) // only some compilers [which ones ?] BOOST_SERIALIZATION_NVP(data) // shortcut if object name acceptable [1] BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base) // shortcut if object name acceptable [2] BOOST_SERIALIZATION_SPLIT_MEMBER() // 'serialize' to 'save'/'load' BOOST_SERIALIZATION_SHARED_PTR(Class) // depreciated [3] BOOST_CLASS_TRACKING(MyVirtualBaseClass, boost::serialization::track_always) BOOST_SHARED_POINTER_EXPORT(T) // depreciated from Boost version 1.32 BOOST_SHARED_POINTER_EXPORT_GUID(T, K) // depreciated from Boost version 1.32 BOOST_SERIALIZATION_LIBRARY_VERSION // yields a "release" number [4] [1] boost::serialization::make_nvp("data", data); [2] requires #include <boost/serialization/base_object.hpp> [3] more specifically, for types without tracking set, that is using boost::serialization::track_never also under 1.34.1 this generates code only for particular Metrowerks and Borland compilers [4] requires #include <boost/serialization/serialization.hpp> (but doesn't appear to be maintained) I don't mind drafting out such a page. Could it be part of the official web documentation or would I be better to add it to the boost wiki as an informal contribution. many thanks in advance Robbie --- Robbie Morrison PhD student -- policy-oriented energy system simulation Institute for Energy Engineering (IET) Technical University of Berlin (TU-Berlin), Germany [from IMAP client]
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net