Boost logo

Boost Users :

From: David Parks (davidp_at_[hidden])
Date: 2005-12-04 11:22:50


First off, I apologize for not replying directly to my last message but
I'm not even sure it's been posted yet -- as I don't have permission to
post yet (the 'first message is moderated' deal).

Anyway, I wasn't able to make the example in my last post work with any
sane process but I did get it to work by doing the following:

1) splitting the stuff into 3 files -- the main driver, the class
header, and the class .cpp. I put both classes in the class files.
2) Including the */archive/* files in the class cpp immediately followed
by export.hpp... then the class header.
3) Including the same archive headers in the class header followed by
serialization.hpp (I'm sure this could be done lighter but...)
4) Including only the class header in main.
5) BOOST_CLASS_EXPORT(derived) in the class cpp.
6) This is where it starts to diverge from any information in the
tutorials and documentation. First, I had to switch from text to xml.
I'm not positive but, if I couldn't get it to work after 12 straight
hours, I'd guess the text interface is broken.
7) You will get a pretty incorrect error (in the header comments) if you
don't call the base class in the derived class serialization (ar &
BOOST_SERIALIZATION_BASE_OBJECT_NVP(base);). This is not ideal because
in many instances, like mine, you might not care about the bases
serialization if you have a derived class... the derived class is
'smarter'. But this I can deal with.

What I needed to do was serialize a vector of objects of some base class
-- you know, like the useless circles and squares of shapes example in
every intro C++ book. The documentation could use this as an example --
it has to be one of the most common uses for a serializer.

Oh, one goofy note that thankfully only took a couple of minutes to
catch: namespaces aren't all the rage but if you make big use of them
(like me), beware of BOOST_CLASS_EXPORT... it takes a flash of
inspiration to realize that it's going to try to put colons in your XML
tags. Even more tricky is the situation where you are calling, say, the
base-class with BOOST_SERIALIZATION_BASE_OBJECT_NVP. It stringizes this
without telling you -- it has to. But if you do this

ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(A::B)

you will get an error but this (thankfully)

using namespace A;
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(B);

works. I have no idea how to make this friendly.

Best,
- David


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