]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/archive/impl/xml_woarchive_impl.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / archive / impl / xml_woarchive_impl.ipp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // xml_woarchive_impl.ipp:
3
4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 #include <boost/config.hpp>
10 #ifndef BOOST_NO_STD_WSTREAMBUF
11
12 #include <ostream>
13 #include <string>
14 #include <algorithm> // std::copy
15 #include <locale>
16 #include <exception>
17
18 #include <cstring> // strlen
19 #include <cstdlib> // mbtowc
20 #ifndef BOOST_NO_CWCHAR
21 #include <cwchar> // wcslen
22 #endif
23
24 #include <boost/config.hpp>
25 #if defined(BOOST_NO_STDC_NAMESPACE)
26 namespace std{
27 using ::strlen;
28 #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
29 using ::mbtowc;
30 using ::wcslen;
31 #endif
32 } // namespace std
33 #endif
34
35 #include <boost/archive/xml_woarchive.hpp>
36 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
37
38 #include <boost/serialization/throw_exception.hpp>
39
40 #include <boost/archive/iterators/xml_escape.hpp>
41 #include <boost/archive/iterators/wchar_from_mb.hpp>
42 #include <boost/archive/iterators/ostream_iterator.hpp>
43 #include <boost/archive/iterators/dataflow_exception.hpp>
44
45 namespace boost {
46 namespace archive {
47
48 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
49 // implemenations of functions specific to wide char archives
50
51 // copy chars to output escaping to xml and widening characters as we go
52 template<class InputIterator>
53 void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){
54 typedef iterators::wchar_from_mb<
55 iterators::xml_escape<InputIterator>
56 > xmbtows;
57 std::copy(
58 xmbtows(begin),
59 xmbtows(end),
60 boost::archive::iterators::ostream_iterator<wchar_t>(os)
61 );
62 }
63
64 template<class Archive>
65 BOOST_WARCHIVE_DECL void
66 xml_woarchive_impl<Archive>::save(const std::string & s){
67 // note: we don't use s.begin() and s.end() because dinkumware
68 // doesn't have string::value_type defined. So use a wrapper
69 // around these values to implement the definitions.
70 const char * begin = s.data();
71 const char * end = begin + s.size();
72 save_iterator(os, begin, end);
73 }
74
75 #ifndef BOOST_NO_STD_WSTRING
76 template<class Archive>
77 BOOST_WARCHIVE_DECL void
78 xml_woarchive_impl<Archive>::save(const std::wstring & ws){
79 #if 0
80 typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
81 std::copy(
82 xmbtows(ws.begin()),
83 xmbtows(ws.end()),
84 boost::archive::iterators::ostream_iterator<wchar_t>(os)
85 );
86 #endif
87 typedef iterators::xml_escape<const wchar_t *> xmbtows;
88 std::copy(
89 xmbtows(ws.data()),
90 xmbtows(ws.data() + ws.size()),
91 boost::archive::iterators::ostream_iterator<wchar_t>(os)
92 );
93 }
94 #endif //BOOST_NO_STD_WSTRING
95
96 template<class Archive>
97 BOOST_WARCHIVE_DECL void
98 xml_woarchive_impl<Archive>::save(const char * s){
99 save_iterator(os, s, s + std::strlen(s));
100 }
101
102 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
103 template<class Archive>
104 BOOST_WARCHIVE_DECL void
105 xml_woarchive_impl<Archive>::save(const wchar_t * ws){
106 typedef iterators::xml_escape<const wchar_t *> xmbtows;
107 std::copy(
108 xmbtows(ws),
109 xmbtows(ws + std::wcslen(ws)),
110 boost::archive::iterators::ostream_iterator<wchar_t>(os)
111 );
112 }
113 #endif
114
115 template<class Archive>
116 BOOST_WARCHIVE_DECL
117 xml_woarchive_impl<Archive>::xml_woarchive_impl(
118 std::wostream & os_,
119 unsigned int flags
120 ) :
121 basic_text_oprimitive<std::wostream>(
122 os_,
123 true // don't change the codecvt - use the one below
124 ),
125 basic_xml_oarchive<Archive>(flags)
126 {
127 if(0 == (flags & no_codecvt)){
128 archive_locale = std::locale(
129 os_.getloc(),
130 new boost::archive::detail::utf8_codecvt_facet
131 );
132 os_.flush();
133 os_.imbue(archive_locale);
134 }
135 if(0 == (flags & no_header))
136 this->init();
137 }
138
139 template<class Archive>
140 BOOST_WARCHIVE_DECL
141 xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
142 if(std::uncaught_exception())
143 return;
144 if(0 == (this->get_flags() & no_header)){
145 os << L"</boost_serialization>";
146 }
147 }
148
149 template<class Archive>
150 BOOST_WARCHIVE_DECL void
151 xml_woarchive_impl<Archive>::save_binary(
152 const void *address,
153 std::size_t count
154 ){
155 this->end_preamble();
156 #if ! defined(__MWERKS__)
157 this->basic_text_oprimitive<std::wostream>::save_binary(
158 #else
159 this->basic_text_oprimitive::save_binary(
160 #endif
161 address,
162 count
163 );
164 this->indent_next = true;
165 }
166
167 } // namespace archive
168 } // namespace boost
169
170 #endif //BOOST_NO_STD_WSTREAMBUF