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