|
Boost Users : |
From: RIVASSEAU Jean Noel (JN.RIVASSEAU_at_[hidden])
Date: 2006-01-10 04:38:51
Hello,
I am trying to learn the Boost Serialization Library. Although I like the fundamental principles of the library, using the library so far has proven a nightmare for my project.
To be more precise: I need to serialize objects via pointers to base class. And I need to do it without RTTI. While using extended_type_info_no_rtti for my classes I always get an "unregistered_class" exception at run time.
But I have done the following: in all my classes, in the implementation unit (.cpp) I have included explicitely the headers needed for the archives I use:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
Then I have something like that in each class:
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/type_info_implementation.hpp>
#include <boost/serialization/extended_type_info_no_rtti.hpp>
#include <boost/serialization/export.hpp>
namespace boost {
namespace serialization {
template<class Archive>
void serialize(Archive & ar, PrimitiveMemberVariableSpecification & m, const unsigned int version)
{
ar & boost::serialization::base_object<MemberVariableSpecification>(m);
ar & m.unused_primitive_type;
}
} // namespace serialization
} // namespace boost
BOOST_CLASS_TYPE_INFO(
PrimitiveMemberVariableSpecification,
extended_type_info_no_rtti<PrimitiveMemberVariableSpecification>
)
BOOST_CLASS_EXPORT(PrimitiveMemberVariableSpecification)
(Here the name of the class is PrimitiveMemberVariableSpecification.
I also want to report a bug in the documentation: the doc says that you should write:
BOOST_CLASS_TYPE_INFO(
ClassName,
extended_type_info_no_rtti<BaseClassName>
)
Although the example test_no_rtti.cpp uses the following syntax:
BOOST_CLASS_TYPE_INFO(
ClassName,
extended_type_info_no_rtti<ClassName>
)
I think that the example is right, not the documentation.
)
Normally the BOOST_CLASS_EXPORT should *register* all my classes. Why doesn't it work? I have of course also written a correct get_key() virtual function for all my classes.
If I just change extended_type_info_no_rtti to extended_type_info_typeid, everything works fine, but I do want extended_type_info_no_rtti.
Also, keeping everything in the headers files seems to be a nightmare, although that is what Robert Ramsey recommends. I get tons of multiple definitions errors at link time if I do that (something like: multiple definition of `boost::archive::detail::guid_initializer<MemberVariableSpecification>::instance' with gcc - MinGW 3.4.2)
I have looked at the documentation for two days, read absolutely everything and still do not understand. Maybe I should look at the code ???
Thank you
Jean-Noël
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