Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-04-28 23:44:52


Joseph Hosteny wrote:
> Hi all,
>
> I'm a relative newbie at using the serialization libraries, so
> please go easy on me, but I'm having some troubles which I can't seem
> to work out.
>
> I have a class hierarchy that looks something like this:
>
> A -> B -> C -> D
>
> There is a corresponding header, and at least one source file, for
> each of the four classes.
>
> The base class, A, contains only methods, but is not a pure virtual
> class. Class B contains the first set of data members in the chain
> that must be serialized. Classes C and D contain some more methods
> and data. All stores/loads will be handled via pointers to instances
> of class D.
>
> Now, the header file for class B contains the following:
>
> #include <boost/archive/text_iarchive.hpp>
> #include <boost/archive/text_oarchive.hpp>

Note - my suggestion is to not include *archive.hpp files in other *.hpp
files. In this case I don't thnk it matters.

> #include <boost/serialization/access.hpp>
> #include <boost/serialization/base_object.hpp>
>
> Classes B, C and D define the following as public:
>
> friend class boost::serialization::access;
> template<class Archive> void serialize(Archive &ar, const unsigned
> int version);
>
> The serialize methods for classes C and D call the base class
> implementations of these methods via:
>
> ar & boost::serialization::base_object<base_class>(*this);
>
> Finally, the source files for classes B, C and D contain:
>
> #include <boost/serialization/export.hpp>
> BOOST_CLASS_EXPORT(class_name);
>
> It's not clear to me, though, that I should need the EXPORT macro
> since all loads/stores are done with the most derived class' pointers.

I don't think that this should be necessary in your case either.

> However, when I run this code, I get an exception at
> oserialization.hpp line 394, which is of type
> archive_exception::unregistered type.

> I've looked through a lot of the documentation, but can't seem to
> find out what I'm doing wrong. I've also tried explicit calls to
> boost::serialization::void_cast_register<base_class, derived_class>
> (), but that didn't seem to work either.
>
> Since this is being retrofitted to a large design, I tried to
> distill what I was trying to do into a sample project with just empty
> classes with the same hierarchy and boot methods/macros. When I do
> this, everything seems to work fine.

Hmm - just keep adding stuff back in until it cracks.
>
> Does anyone have any suggestions on what I should look for that may
> be screwing things up for me? I can send the sample files I used, but
> since these work, I'm not sure if they will be of much help. Any
> pointers will be greatly appreciated!

you might try doing explicit "register" for classes A, B.. D. That should
make thigns work. If it does you can either just declare victory or
continue on to find the problem

Robert Ramey


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