#include #include #include #include #include #include #include class unit { public: unit() : id_(0) { } unit(int id) : id_(id) { } template void serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(id_); } private: int id_; }; class test_oarchive : public boost::archive::detail::common_oarchive { friend class boost::archive::save_access; friend class boost::archive::detail::interface_oarchive; public: test_oarchive(std::ostream& out, unsigned int = 0) : out_(out){ } void save_binary(const void* address, std::size_t count) { out_.write(static_cast(address), count); } template void save(const T& t) { out_ << t; } void save(const std::wstring& s) { } template void save_override(const boost::serialization::nvp& nvp, int f) { out_ << ""; typedef boost::archive::detail::common_oarchive detail_common_oarchive; this->detail_common_oarchive::save_override(nvp.const_value(), f); out_ << "\n"; } void save_override(const boost::archive::object_id_type & t, int) { } void save_override(const boost::archive::object_reference_type & t, int) { } void save_override(const boost::archive::version_type & t, int) { } void save_override(const boost::archive::class_id_type & t, int) { } void save_override(const boost::archive::class_id_optional_type & t, int) { } void save_override(const boost::archive::class_id_reference_type & t, int) { } void save_override(const boost::archive::class_name_type & t, int) { } void save_override(const boost::archive::tracking_type & t, int) { } private: std::ostream& out_; }; typedef boost::archive::detail::polymorphic_oarchive_route polymorphic_test_oarchive; namespace boost { namespace archive { template class detail::archive_serializer_map; template class detail::archive_serializer_map; } } BOOST_SERIALIZATION_REGISTER_ARCHIVE(test_oarchive) BOOST_SERIALIZATION_REGISTER_ARCHIVE(polymorphic_test_oarchive) int main() { unit u(42); { std::cout << "template:" << std::endl; test_oarchive ar(std::cout); ar << BOOST_SERIALIZATION_NVP(u); std::cout << std::endl; } { std::cout << "polymorphic:" << std::endl; polymorphic_test_oarchive ar(std::cout); ar << BOOST_SERIALIZATION_NVP(u); std::cout << std::endl; } }