|
Boost : |
From: Neal Becker (ndbecker2_at_[hidden])
Date: 2006-09-14 11:10:52
I noticed that if I use both BOOST_CLASS_EXPORT and register_type it causes
an error. Here is an example:
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <iostream>
#include <sstream>
#include <boost/serialization/extended_type_info_typeid.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/nvp.hpp>
struct base {
double min, max;
base (double _min, double _max) : min (_min), max (_max) {}
base(){}
template<class Archive>
inline void serialize (Archive &ar, const unsigned int) {
ar & BOOST_SERIALIZATION_NVP(min);
ar & BOOST_SERIALIZATION_NVP(max);
}
virtual int noop() = 0;
};
struct derived : public base {
derived (double _min, double _max) : base (_min, _max) {}
derived(){}
template<class Archive>
inline void serialize (Archive &ar, const unsigned int) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP (base);
}
int noop() { return 1; }
};
#include <boost/serialization/export.hpp>
BOOST_CLASS_EXPORT (derived)
struct A {
base* b;
A (base* _b) : b (_b) {}
A() {}
template<class Archive>
void save (Archive & ar, const unsigned int version) const {
ar.register_type (static_cast<derived*>(NULL)); <<< comment/uncomment
this line
std::cout << b->min << ' ' << b->max << '\n';
ar << BOOST_SERIALIZATION_NVP(b);
}
template<class Archive>
void load (Archive & ar, const unsigned int version) {
base* b = NULL;
ar >> BOOST_SERIALIZATION_NVP(b);
std::cout << b->min << ' ' << b->max << '\n';
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
};
int main() {
derived* p = new derived (1,2);
const A a (p);
std::stringstream ss;
boost::archive::text_oarchive oa (ss);
oa << a;
ss.seekg (0);
// std::cout << ss.str() << '\n';
ss.seekg (0);
boost::archive::text_iarchive ia (ss);
A b;
ia >> b;
}
If ar.register_type is there, you get unregistered exception.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk