help with serialization (invalid use of underined type)

Can anyone see what's wrong with this example? #include <stdexcept> #include <boost/shared_ptr.hpp> #include <boost/serialization/split_member.hpp> #include <boost/serialization/nvp.hpp> #include <boost/serialization/shared_ptr.hpp> template<typename value_t> struct overflow_policy_base { overflow_policy_base (value_t _min, value_t _max) : min (_min), max (_max) {} virtual value_t apply (value_t) = 0; // virtual value_t apply (value_t); value_t min, max; friend class boost::serialization::access; template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & this->min; ar & this->max; } }; template<typename value_t> struct limit_policy : public overflow_policy_base<value_t> { limit_policy (value_t _min, value_t _max) : overflow_policy_base<value_t> (_min, _max) {} virtual value_t apply (value_t x) { if (x > this->max) return this->max; else if (x < this->min) return this->min; else return x; } template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & boost::serialization::base_object<overflow_policy_base<value_t> >(*this); } }; template<typename value_t> struct throw_policy : public overflow_policy_base<value_t> { throw_policy (value_t _min, value_t _max) : overflow_policy_base<value_t> (_min, _max) {} virtual value_t apply (value_t x) { if (x > this->max or x < this->min) throw std::runtime_error ("Histogram value out of range"); else return x; } template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & boost::serialization::base_object<overflow_policy_base<value_t> >(*this); } }; #include <boost/serialization/export.hpp> BOOST_SERIALIZATION_SHARED_PTR (limit_policy<double>) BOOST_CLASS_EXPORT_GUID (limit_policy<double>, "limit_policy<double>") g++ -I /usr/local/src/boost.cvs -xc++ -fsyntax-only test.hpp /usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp: In instantiation of ‘boost::serialization::type_info_implementation<limit_policy<double> >’: /usr/local/src/boost.cvs/boost/serialization/export.hpp:76: instantiated from ‘boost::archive::detail::guid_initializer<limit_policy<double> >’ test.hpp:64: instantiated from here /usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp:50: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_impl<limit_policy<double> >’ /usr/local/src/boost.cvs/boost/serialization/traits.hpp:42: error: declaration of ‘struct boost::serialization::extended_type_info_impl<limit_policy<double> >’

Simplified example (same problem): #include <stdexcept> #include <boost/serialization/nvp.hpp> #include <boost/serialization/export.hpp> struct overflow_policy_base2 { overflow_policy_base2 (double _min, double _max) : min (_min), max (_max) {} virtual double apply (double) = 0; double min, max; friend class boost::serialization::access; template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & min; ar & max; } }; BOOST_IS_ABSTRACT (overflow_policy_base2) struct limit_policy2 : public overflow_policy_base2 { limit_policy2 (double _min, double _max) : overflow_policy_base2 (_min, _max) {} virtual double apply (double x) { if (x > this->max) return this->max; else if (x < this->min) return this->min; else return x; } template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP (overflow_policy_base2); } }; BOOST_CLASS_EXPORT (limit_policy2) g++ -I /usr/local/src/boost.cvs -xc++ -fsyntax-only test.hpp /usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp: In instantiation of ‘boost::serialization::type_info_implementation<limit_policy2>’: /usr/local/src/boost.cvs/boost/serialization/export.hpp:76: instantiated from ‘boost::archive::detail::guid_initializer<limit_policy2>’ test.hpp:43: instantiated from here /usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp:50: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_impl<limit_policy2>’ /usr/local/src/boost.cvs/boost/serialization/traits.hpp:42: error: declaration of ‘struct boost::serialization::extended_type_info_impl<limit_policy2>’

From: Neal Becker
Can anyone see what's wrong with this example?
[snip the code] Hi Neal, I see you might be trying to solve the problem I'm already solving - the bounded types. I know I was saying I'll finish the library long ago, but unfortunately other activities didn't allow me to. However, I'm hoping to be able to work on it soon. If you're interested, please let me know - I can send you the current code and documentation. Best regards, Robert

Which version of boost is being used here? export in HEAD is difffernent from that in boost 1.34, 1.33, etc so we need to know in order to address this. Robert Ramey Neal Becker wrote:
Can anyone see what's wrong with this example?
#include <stdexcept> #include <boost/shared_ptr.hpp> #include <boost/serialization/split_member.hpp> #include <boost/serialization/nvp.hpp> #include <boost/serialization/shared_ptr.hpp>
template<typename value_t> struct overflow_policy_base { overflow_policy_base (value_t _min, value_t _max) : min (_min), max (_max) {} virtual value_t apply (value_t) = 0; // virtual value_t apply (value_t); value_t min, max;
friend class boost::serialization::access;
template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & this->min; ar & this->max; } };
template<typename value_t> struct limit_policy : public overflow_policy_base<value_t> { limit_policy (value_t _min, value_t _max) : overflow_policy_base<value_t> (_min, _max) {}
virtual value_t apply (value_t x) { if (x > this->max) return this->max; else if (x < this->min) return this->min; else return x; }
template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & boost::serialization::base_object<overflow_policy_base<value_t>
(*this); } };
template<typename value_t> struct throw_policy : public overflow_policy_base<value_t> { throw_policy (value_t _min, value_t _max) : overflow_policy_base<value_t> (_min, _max) {}
virtual value_t apply (value_t x) { if (x > this->max or x < this->min) throw std::runtime_error ("Histogram value out of range"); else return x; }
template<class Archive> inline void serialize (Archive &ar, const unsigned int) { ar & boost::serialization::base_object<overflow_policy_base<value_t>
(*this); } };
#include <boost/serialization/export.hpp> BOOST_SERIALIZATION_SHARED_PTR (limit_policy<double>) BOOST_CLASS_EXPORT_GUID (limit_policy<double>, "limit_policy<double>")
g++ -I /usr/local/src/boost.cvs -xc++ -fsyntax-only test.hpp /usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp: In instantiation of 'boost::serialization::type_info_implementation<limit_policy<double>
': /usr/local/src/boost.cvs/boost/serialization/export.hpp:76: instantiated from 'boost::archive::detail::guid_initializer<limit_policy<double> >' test.hpp:64: instantiated from here /usr/local/src/boost.cvs/boost/serialization/type_info_implementation.hpp:50: error: invalid use of undefined type 'struct boost::serialization::extended_type_info_impl<limit_policy<double> >' /usr/local/src/boost.cvs/boost/serialization/traits.hpp:42: error: declaration of 'struct boost::serialization::extended_type_info_impl<limit_policy<double> >'
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

"Robert Ramey" <ramey@rrsd.com> writes:
Which version of boost is being used here? export in HEAD is difffernent from that in boost 1.34, 1.33, etc so we need to know in order to address this.
Robert Ramey
Neal Becker wrote:
Can anyone see what's wrong with this example?
<snip long quote> http://www.boost.org/more/discussion_policy.htm#effective, please. Thanks, -- Dave Abrahams Boost Consulting www.boost-consulting.com

Neal Becker wrote:
Can anyone see what's wrong with this example?
<snip> The concept of "Export" is not necessary except for polymorphic types. Application to non-polymorphic types currently fails in a confusing manner. Fix - comment out the following: //BOOST_SERIALIZATION_SHARED_PTR (limit_policy<double>) //BOOST_CLASS_EXPORT_CHECK (limit_policy<double>) //BOOST_CLASS_EXPORT_GUID (limit_policy<double>, "limit_policy<double>") If you want to serialize derived classes - then make one of the functions virtual and export the derived classes. Robert Ramey
participants (4)
-
David Abrahams
-
Neal Becker
-
Robert Kawulak
-
Robert Ramey