//---------------------------------------------------------------------------- // Serializer.h // Copyright (c) 2006 Move Interactive // // //---------------------------------------------------------------------------- #ifndef _FLOWENGINE_CORE_SERIALIZER_BINARYSERIALIZER_H_ #define _FLOWENGINE_CORE_SERIALIZER_BINARYSERIALIZER_H_ #include "core/serialization/Serializer.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace FlowEngine { class BinaryArchiveO : public IArchive, // don't derive from binary_oarchive !!! public boost::archive::binary_oarchive_impl { typedef BinaryArchiveO derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::detail::interface_oarchive; friend class boost::archive::basic_binary_oarchive; friend class boost::archive::basic_binary_oprimitive; friend class boost::archive::save_access; #endif // add base class to the places considered when matching // save function to a specific set of arguments. Note, this didn't // work on my MSVC 7.0 system // using boost::archive::binary_oarchive_impl::load_override; // so we use the sure-fire method below. This failed to work as well template void save_override(T & t, BOOST_PFTO int){ boost::archive::binary_oarchive_impl::save_override(t, 0); // verify that this program is in fact working by making sure // that arrays are getting passed here BOOST_STATIC_ASSERT(! (boost::is_array::value) ); } template void save_override(const int (& t)[N] , int){ save_binary(t, sizeof(t)); } template void save_override(const unsigned int (& t)[N], int){ save_binary(t, sizeof(t)); } template void save_override(const long (& t)[N], int){ save_binary(t, sizeof(t)); } template void save_override(const unsigned long (& t)[N], int){ save_binary(t, sizeof(t)); } public: BinaryArchiveO(std::ostream & os, unsigned flags = 0) : boost::archive::binary_oarchive_impl(os, flags) {} virtual void Serialize(int& t) { *this & BOOST_SERIALIZATION_NVP(t); } virtual void Serialize(bool& t) { *this & BOOST_SERIALIZATION_NVP(t); } }; class BinaryArchiveI : public IArchive, // don't derive from binary_oarchive !!! public boost::archive::binary_iarchive_impl { typedef BinaryArchiveI derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::detail::interface_iarchive; friend class boost::archive::basic_binary_iarchive; friend class boost::archive::basic_binary_iprimitive; friend class boost::archive::load_access; #endif // add base class to the places considered when matching // save function to a specific set of arguments. Note, this didn't // work on my MSVC 7.0 system // using binary_oarchive_impl::load_override; // so we use the sure-fire method below. This failed to work as well template void load_override(T & t, BOOST_PFTO int){ boost::archive::binary_iarchive_impl::load_override(t, 0); BOOST_STATIC_ASSERT(! (boost::is_array::value) ); } template void load_override(int (& t)[N], int){ load_binary(t, sizeof(t)); } template void load_override(unsigned int (& t)[N], int){ load_binary(t, sizeof(t)); } template void load_override(long (& t)[N], int){ load_binary(t, sizeof(t)); } template void load_override(unsigned long (& t)[N], int){ load_binary(t, sizeof(t)); } public: BinaryArchiveI(std::istream & is, unsigned flags = 0) : boost::archive::binary_iarchive_impl(is,flags) {} virtual void Serialize(int& t) { *this & BOOST_SERIALIZATION_NVP(t); } virtual void Serialize(bool& t) { *this & BOOST_SERIALIZATION_NVP(t); } }; } #endif