Hi,
boost::serialization is wonderful. It has saved a massive amount of effort when adding XML based storage to an existing C++ drawing library. A very big thank you to the author and the team.
Questions arising:
1. After one or two crash & burn cycles i discovered the need to register derived classes in the 'save through a virtual base class pointer' scenario. Right now this is done when saving to/loading from the archive. Is there an alternative to this method that ensures registration occurs automatically? i'm sure this is a FAQ but cannot find a definitive answer.
i..e
// XML archive
boost::archive::xml_iarchive ia(ifs);
// ensure derived types are registered - too easy to forget, what's the better way?
ia.register_type(static_cast
Jerry wrote:
Hi,
boost::serialization is wonderful. It has saved a massive amount of effort when adding XML based storage to an existing C++ drawing library. A very big thank you to the author and the team.
Questions arising:
1. After one or two crash & burn cycles i discovered the need to register derived classes in the 'save through a virtual base class pointer' scenario. Right now this is done when saving to/loading from the archive. Is there an alternative to this method that ensures registration occurs automatically? i'm sure this is a FAQ but cannot find a definitive answer.
i..e
// XML archive boost::archive::xml_iarchive ia(ifs); // ensure derived types are registered - too easy to forget, what's the better way? ia.register_type(static_cast
(NULL));
Look for the BOOST_...EXPORT macros, but they're still not automatic.
2. Serializing to a binary storage should be a great way to implement undo/redo and clipboard functionality - has anyone found fame and fortune doing this?
Yes, use the boost::iostream library to create a stream that wraps your clipboard or other binary storage. Jeff Flinn
Jeff Flinn wrote:
2. Serializing to a binary storage should be a great way to implement undo/redo and clipboard functionality - has anyone found fame and fortune doing this?
Yes, use the boost::iostream library to create a stream that wraps your clipboard or other binary storage.
Jeff Flinn
Ahhh - you actually found fame and fortune doing this? Robert Ramey
Robert Ramey wrote:
Jeff Flinn wrote:
2. Serializing to a binary storage should be a great way to implement undo/redo and clipboard functionality - has anyone found fame and fortune doing this? Yes, use the boost::iostream library to create a stream that wraps your clipboard or other binary storage.
Jeff Flinn
Ahhh - you actually found fame and fortune doing this?
Robert Ramey
In my own mind. :-) My elbow still suffers from patting myself on the back. Jeff Flinn
Jeff, thanks.
Look for the BOOST_...EXPORT macros, but they're still not automatic.
Yep, that does it. Certainly automatic enough. For anyone searching the archives I think this is the archetype: //---------header file----------- // example derived serializable class class derived : public base { std::string m_name; friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const unsigned int /*version*/) { // serialize base class ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(base); // handle any members in derived ar & BOOST_SERIALIZATION_NVP(m_name); } public: derived() {} }; // ensure correct ID generation when saving via base* // if this is omitted you'll get an unregistered exception unless // you register each class directly with the archive BOOST_CLASS_EXPORT_GUID(derived,"derived") //---------/header file-----------
Be warned that this is not thread-safe in the currently released versions of Boost. I meant to inspect the latest version for thread-safety but haven't got around to it (sorry Robert!) On Tue, 11 Mar 2008 20:17:13 +0000, Jerry wrote:
Jeff, thanks.
Look for the BOOST_...EXPORT macros, but they're still not automatic.
Yep, that does it. Certainly automatic enough.
For anyone searching the archives I think this is the archetype:
//---------header file-----------
// example derived serializable class class derived : public base { std::string m_name; friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const unsigned int /*version*/) { // serialize base class ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(base); // handle any members in derived ar & BOOST_SERIALIZATION_NVP(m_name); } public: derived() {} };
// ensure correct ID generation when saving via base* // if this is omitted you'll get an unregistered exception unless // you register each class directly with the archive BOOST_CLASS_EXPORT_GUID(derived,"derived")
//---------/header file-----------
-- Sohail Somani http://uint32t.blogspot.com
I believe the latest version at www.rrsd.com is thread safe. I haven't figured out a way to make a definitive test of that proposition. I'm very interested in having those interested in this topic take a look at it and if they can find a way, to test that proposition. Robert Ramey Sohail Somani wrote:
Be warned that this is not thread-safe in the currently released versions of Boost. I meant to inspect the latest version for thread-safety but haven't got around to it (sorry Robert!)
participants (4)
-
Jeff Flinn
-
Jerry
-
Robert Ramey
-
Sohail Somani