1 #ifndef BOOST_ARCHIVE_XML_WOARCHIVE_HPP 2 #define BOOST_ARCHIVE_XML_WOARCHIVE_HPP 3 4 // MS compatible compilers support #pragma once 5 #if defined(_MSC_VER) 6 # pragma once 7 #endif 8 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 10 // xml_woarchive.hpp 11 12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 13 // Use, modification and distribution is subject to the Boost Software 14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 15 // http://www.boost.org/LICENSE_1_0.txt) 16 17 // See http://www.boost.org for updates, documentation, and revision history. 18 19 #include <boost/config.hpp> 20 #ifdef BOOST_NO_STD_WSTREAMBUF 21 #error "wide char i/o not supported on this platform" 22 #else 23 24 #include <cstddef> // size_t 25 #if defined(BOOST_NO_STDC_NAMESPACE) 26 namespace std{ 27 using ::size_t; 28 } // namespace std 29 #endif 30 31 #include <ostream> 32 33 #include <boost/smart_ptr/scoped_ptr.hpp> 34 #include <boost/archive/detail/auto_link_warchive.hpp> 35 #include <boost/archive/basic_text_oprimitive.hpp> 36 #include <boost/archive/basic_xml_oarchive.hpp> 37 #include <boost/archive/detail/register_archive.hpp> 38 #include <boost/serialization/item_version_type.hpp> 39 40 #ifdef BOOST_NO_CXX11_HDR_CODECVT 41 #include <boost/archive/detail/utf8_codecvt_facet.hpp> 42 #else 43 #include <codecvt> 44 namespace boost { namespace archive { namespace detail { 45 typedef std::codecvt_utf8<wchar_t> utf8_codecvt_facet; 46 } } } 47 #endif 48 49 #include <boost/archive/detail/abi_prefix.hpp> // must be the last header 50 51 #ifdef BOOST_MSVC 52 # pragma warning(push) 53 # pragma warning(disable : 4511 4512) 54 #endif 55 56 namespace boost { 57 namespace archive { 58 59 namespace detail { 60 template<class Archive> class interface_oarchive; 61 } // namespace detail 62 63 template<class Archive> 64 class BOOST_SYMBOL_VISIBLE xml_woarchive_impl : 65 public basic_text_oprimitive<std::wostream>, 66 public basic_xml_oarchive<Archive> 67 { 68 #ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS 69 public: 70 #else 71 protected: 72 #if BOOST_WORKAROUND(BOOST_MSVC, < 1500) 73 // for some inexplicable reason insertion of "class" generates compile erro 74 // on msvc 7.1 75 friend detail::interface_oarchive<Archive>; 76 friend basic_xml_oarchive<Archive>; 77 friend save_access; 78 #else 79 friend class detail::interface_oarchive<Archive>; 80 friend class basic_xml_oarchive<Archive>; 81 friend class save_access; 82 #endif 83 #endif 84 //void end_preamble(){ 85 // basic_xml_oarchive<Archive>::end_preamble(); 86 //} 87 template<class T> 88 void save(const T & t)89 save(const T & t){ 90 basic_text_oprimitive<std::wostream>::save(t); 91 } 92 void save(const version_type & t)93 save(const version_type & t){ 94 save(static_cast<const unsigned int>(t)); 95 } 96 void save(const boost::serialization::item_version_type & t)97 save(const boost::serialization::item_version_type & t){ 98 save(static_cast<const unsigned int>(t)); 99 } 100 BOOST_WARCHIVE_DECL void 101 save(const char * t); 102 #ifndef BOOST_NO_INTRINSIC_WCHAR_T 103 BOOST_WARCHIVE_DECL void 104 save(const wchar_t * t); 105 #endif 106 BOOST_WARCHIVE_DECL void 107 save(const std::string &s); 108 #ifndef BOOST_NO_STD_WSTRING 109 BOOST_WARCHIVE_DECL void 110 save(const std::wstring &ws); 111 #endif 112 BOOST_WARCHIVE_DECL 113 xml_woarchive_impl(std::wostream & os, unsigned int flags); 114 BOOST_WARCHIVE_DECL 115 ~xml_woarchive_impl(); 116 public: 117 void save_binary(const void * address,std::size_t count)118 save_binary(const void *address, std::size_t count){ 119 this->end_preamble(); 120 #if ! defined(__MWERKS__) 121 this->basic_text_oprimitive<std::wostream>::save_binary( 122 #else 123 this->basic_text_oprimitive::save_binary( 124 #endif 125 address, 126 count 127 ); 128 this->indent_next = true; 129 } 130 }; 131 132 // we use the following because we can't use 133 // typedef xml_woarchive_impl<xml_woarchive_impl<...> > xml_woarchive; 134 135 // do not derive from this class. If you want to extend this functionality 136 // via inhertance, derived from xml_woarchive_impl instead. This will 137 // preserve correct static polymorphism. 138 class BOOST_SYMBOL_VISIBLE xml_woarchive : 139 public xml_woarchive_impl<xml_woarchive> 140 { 141 public: xml_woarchive(std::wostream & os,unsigned int flags=0)142 xml_woarchive(std::wostream & os, unsigned int flags = 0) : 143 xml_woarchive_impl<xml_woarchive>(os, flags) 144 {} ~xml_woarchive()145 ~xml_woarchive(){} 146 }; 147 148 } // namespace archive 149 } // namespace boost 150 151 // required by export 152 BOOST_SERIALIZATION_REGISTER_ARCHIVE(boost::archive::xml_woarchive) 153 154 #ifdef BOOST_MSVC 155 #pragma warning(pop) 156 #endif 157 158 #include <boost/archive/detail/abi_suffix.hpp> // pops abi_suffix.hpp pragmas 159 160 #endif // BOOST_NO_STD_WSTREAMBUF 161 #endif // BOOST_ARCHIVE_XML_OARCHIVE_HPP 162