//---------------------------------------------------------------------------- // Serializer.h // Copyright (c) 2006 Move Interactive // // //---------------------------------------------------------------------------- #ifndef _FLOWENGINE_CORE_SERIALIZER_XMLSERIALIZER_H_ #define _FLOWENGINE_CORE_SERIALIZER_XMLSERIALIZER_H_ #include "core/serialization/Serializer.h" #include #include #include #include #include #include //#include //#include #include #include #include #include namespace FlowEngine { class XMLArchiveO : public IArchive, // don't derive from xml_oarchive !!! public boost::archive::xml_oarchive_impl { typedef XMLArchiveO derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::detail::interface_oarchive; friend class boost::archive::basic_xml_oarchive; 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::xml_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::xml_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: XMLArchiveO(std::ostream & os, unsigned flags = 0) : boost::archive::xml_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 XMLArchiveI : public IArchive, // don't derive from xml_oarchive !!! public boost::archive::xml_iarchive_impl { typedef XMLArchiveI derived_t; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS public: #else friend class boost::archive::detail::interface_iarchive; friend class boost::archive::basic_xml_iarchive; 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 xml_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::xml_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: XMLArchiveI(std::istream & is, unsigned flags = 0) : boost::archive::xml_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