//---------------------------------------------------------------------------- // Serializer.h // Copyright (c) 2006 Move Interactive // // //---------------------------------------------------------------------------- #ifndef _FLOWENGINE_CORE_SERIALIZER_TEXTSERIALIZER_H_ #define _FLOWENGINE_CORE_SERIALIZER_TEXTSERIALIZER_H_ #include "core/serialization/Serializer.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace FlowEngine { class TextArchiveO : public IArchive, // don't derive from text_oarchive !!! public boost::archive::text_oarchive_impl { typedef TextArchiveO derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::detail::common_oarchive; friend class boost::archive::detail::interface_oarchive; friend class boost::archive::basic_text_oarchive; friend class boost::archive::basic_text_oprimitive; friend class boost::archive::save_access; protected: #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::text_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::text_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: TextArchiveO(std::ostream & os, unsigned flags = 0) : boost::archive::text_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 TextArchiveI : public IArchive, // don't derive from text_oarchive !!! public boost::archive::text_iarchive_impl { typedef TextArchiveI derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::detail::interface_iarchive; friend class boost::archive::basic_text_iarchive; friend class boost::archive::basic_text_iprimitive; friend class boost::archive::load_access; protected: #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 text_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::text_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: TextArchiveI(std::istream & is, unsigned flags = 0) : boost::archive::text_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