File indexing completed on 2025-01-18 09:28:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/config.hpp>
0010 #ifndef BOOST_NO_STD_WSTREAMBUF
0011
0012 #include <ostream>
0013 #include <string>
0014 #include <algorithm> // std::copy
0015 #include <locale>
0016
0017 #include <cstring> // strlen
0018 #include <cstdlib> // mbtowc
0019 #ifndef BOOST_NO_CWCHAR
0020 #include <cwchar> // wcslen
0021 #endif
0022
0023 #include <boost/config.hpp>
0024 #if defined(BOOST_NO_STDC_NAMESPACE)
0025 namespace std{
0026 using ::strlen;
0027 #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
0028 using ::mbtowc;
0029 using ::wcslen;
0030 #endif
0031 }
0032 #endif
0033
0034 #include <boost/core/uncaught_exceptions.hpp>
0035
0036 #include <boost/archive/xml_woarchive.hpp>
0037 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
0038
0039 #include <boost/serialization/throw_exception.hpp>
0040
0041 #include <boost/archive/iterators/xml_escape.hpp>
0042 #include <boost/archive/iterators/wchar_from_mb.hpp>
0043 #include <boost/archive/iterators/ostream_iterator.hpp>
0044 #include <boost/archive/iterators/dataflow_exception.hpp>
0045
0046 namespace boost {
0047 namespace archive {
0048
0049
0050
0051
0052
0053 template<class InputIterator>
0054 void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){
0055 typedef iterators::wchar_from_mb<
0056 iterators::xml_escape<InputIterator>
0057 > xmbtows;
0058 std::copy(
0059 xmbtows(begin),
0060 xmbtows(end),
0061 boost::archive::iterators::ostream_iterator<wchar_t>(os)
0062 );
0063 }
0064
0065 template<class Archive>
0066 BOOST_WARCHIVE_DECL void
0067 xml_woarchive_impl<Archive>::save(const std::string & s){
0068
0069
0070
0071 const char * begin = s.data();
0072 const char * end = begin + s.size();
0073 save_iterator(os, begin, end);
0074 }
0075
0076 #ifndef BOOST_NO_STD_WSTRING
0077 template<class Archive>
0078 BOOST_WARCHIVE_DECL void
0079 xml_woarchive_impl<Archive>::save(const std::wstring & ws){
0080 #if 0
0081 typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
0082 std::copy(
0083 xmbtows(ws.begin()),
0084 xmbtows(ws.end()),
0085 boost::archive::iterators::ostream_iterator<wchar_t>(os)
0086 );
0087 #endif
0088 typedef iterators::xml_escape<const wchar_t *> xmbtows;
0089 std::copy(
0090 xmbtows(ws.data()),
0091 xmbtows(ws.data() + ws.size()),
0092 boost::archive::iterators::ostream_iterator<wchar_t>(os)
0093 );
0094 }
0095 #endif
0096
0097 template<class Archive>
0098 BOOST_WARCHIVE_DECL void
0099 xml_woarchive_impl<Archive>::save(const char * s){
0100 save_iterator(os, s, s + std::strlen(s));
0101 }
0102
0103 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0104 template<class Archive>
0105 BOOST_WARCHIVE_DECL void
0106 xml_woarchive_impl<Archive>::save(const wchar_t * ws){
0107 typedef iterators::xml_escape<const wchar_t *> xmbtows;
0108 std::copy(
0109 xmbtows(ws),
0110 xmbtows(ws + std::wcslen(ws)),
0111 boost::archive::iterators::ostream_iterator<wchar_t>(os)
0112 );
0113 }
0114 #endif
0115
0116 template<class Archive>
0117 BOOST_WARCHIVE_DECL
0118 xml_woarchive_impl<Archive>::xml_woarchive_impl(
0119 std::wostream & os_,
0120 unsigned int flags
0121 ) :
0122 basic_text_oprimitive<std::wostream>(
0123 os_,
0124 true
0125 ),
0126 basic_xml_oarchive<Archive>(flags)
0127 {
0128 if(0 == (flags & no_codecvt)){
0129 archive_locale = std::locale(
0130 os_.getloc(),
0131 new boost::archive::detail::utf8_codecvt_facet
0132 );
0133 os_.flush();
0134 os_.imbue(archive_locale);
0135 }
0136 }
0137
0138 template<class Archive>
0139 BOOST_WARCHIVE_DECL
0140 xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
0141 if(boost::core::uncaught_exceptions() > 0)
0142 return;
0143 if(0 == (this->get_flags() & no_header)){
0144 os << L"</boost_serialization>";
0145 }
0146 }
0147
0148 template<class Archive>
0149 BOOST_WARCHIVE_DECL void
0150 xml_woarchive_impl<Archive>::save_binary(
0151 const void *address,
0152 std::size_t count
0153 ){
0154 this->end_preamble();
0155 #if ! defined(__MWERKS__)
0156 this->basic_text_oprimitive<std::wostream>::save_binary(
0157 #else
0158 this->basic_text_oprimitive::save_binary(
0159 #endif
0160 address,
0161 count
0162 );
0163 this->indent_next = true;
0164 }
0165
0166 }
0167 }
0168
0169 #endif