boost::serialization oserializer weirdness

Using Boost 1.34.1 with VC++ 7.1 SP1
I have existing code which serializes/de-serializes correctly to boost::archive::xml_oarchive
Within the same .cpp file I'm trying to serialize instances of the same hierarchy to boost::archive::binary_oarchive using this code:
// ultimate sink for serialized data
std::ostringstream os;
// binary format is OK as it is going onto the clipboard
boost::archive::binary_oarchive oa(os);
// temp storage
std::vector

On Fri, 21 Mar 2008 02:13:36 +0000, Jerry wrote:
Within the same .cpp file I'm trying to serialize instances of the same hierarchy to boost::archive::binary_oarchive using this code:
Hi, You say this is a hierarchy. In that case, you have to be sure that you have BOOST_CLASS_EXPORTED or otherwise registered the child classes. Though now that I think about it, that should throw an unregistered cast exception iirc. Does that help? -- Sohail Somani http://uint32t.blogspot.com

Thx Sohail
This hierarchy is all registered using BOOST_CLASS_EXPORTED. XML export
works in exactly the same scenario, using binary_oarchive fails.
----- Original Message -----
From: "Sohail Somani"
On Fri, 21 Mar 2008 02:13:36 +0000, Jerry wrote:
Within the same .cpp file I'm trying to serialize instances of the same hierarchy to boost::archive::binary_oarchive using this code:
Hi,
You say this is a hierarchy. In that case, you have to be sure that you have BOOST_CLASS_EXPORTED or otherwise registered the child classes. Though now that I think about it, that should throw an unregistered cast exception iirc.
Does that help?
-- Sohail Somani http://uint32t.blogspot.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Fri, 21 Mar 2008 02:45:40 +0000, Jerry wrote:
Thx Sohail
This hierarchy is all registered using BOOST_CLASS_EXPORTED. XML export works in exactly the same scenario, using binary_oarchive fails.
Might be a long shot, but are you sure you've done this throughout your code: http://www.boost.org/libs/serialization/doc/special.html#export -- Sohail Somani http://uint32t.blogspot.com

Sohail,
Might be a long shot, but are you sure you've done this throughout your code:
http://www.boost.org/libs/serialization/doc/special.html#export
Yes, all done. The failing code is _after_ the check for unregistered classes. No exception is thrown, but the assert() is triggered. BTW here's the general form as I outlined a few weeks back: Can you see any problems. //---------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---------------

a) I don't see any "virtual" in the "general form". For this to work, the base class has to have at least one virtual function. We can't verify this from the code displayed so far. b) My currently recommended practice is that BOOST_CLASS_EXPORT not be in the header but rather in the *.cpp file. Check the updated documents in the trunk. Robert Ramey Jerry wrote:
Sohail,
Might be a long shot, but are you sure you've done this throughout your code:
http://www.boost.org/libs/serialization/doc/special.html#export
Yes, all done. The failing code is _after_ the check for unregistered classes. No exception is thrown, but the assert() is triggered.
BTW here's the general form as I outlined a few weeks back: Can you see any problems.
//---------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---------------

On Fri, 21 Mar 2008 10:48:19 +0000, Jerry wrote:
Sohail,
Might be a long shot, but are you sure you've done this throughout your code:
http://www.boost.org/libs/serialization/doc/special.html#export
Yes, all done. The failing code is _after_ the check for unregistered classes. No exception is thrown, but the assert() is triggered.
Actually, the exception would be triggered in release mode, I think. In any case, assuming you do have a virtual function as Robert suggested, I would strongly recommend a test case along with which version of Boost you are using. -- Sohail Somani http://uint32t.blogspot.com

One thing that I wonder about here. Binary archives, the stream should be opened with ios::binary. I'm not sure how that works with string stream.
Another difference betwen binary and other archives is the special handling for vectors and arrays. I wouldn't think this should matter here, but it might be looked into. Try thsi:
Robert Ramey
"Jerry"

On 20 Mar 2008, at 21:23, Robert Ramey wrote:
Another difference betwen binary and other archives is the special handling for vectors and arrays. I wouldn't think this should matter here, but it might be looked into.
That should not be the case in 1.34.1 yet but only from 1.35 Matthias
participants (4)
-
Jerry
-
Matthias Troyer
-
Robert Ramey
-
Sohail Somani