1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // xml_woarchive_impl.ipp:
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)
9 #include <boost/config.hpp>
10 #ifndef BOOST_NO_STD_WSTREAMBUF
14 #include <algorithm> // std::copy
18 #include <cstring> // strlen
19 #include <cstdlib> // mbtowc
20 #include <cwchar> // wcslen
22 #include <boost/config.hpp>
23 #if defined(BOOST_NO_STDC_NAMESPACE)
26 #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
33 #include <boost/archive/xml_woarchive.hpp>
34 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
36 #include <boost/serialization/throw_exception.hpp>
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>
46 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
47 // implemenations of functions specific to wide char archives
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>
58 boost::archive::iterators::ostream_iterator<wchar_t>(os)
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);
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){
78 typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
82 boost::archive::iterators::ostream_iterator<wchar_t>(os)
85 typedef iterators::xml_escape<const wchar_t *> xmbtows;
88 xmbtows(ws.data() + ws.size()),
89 boost::archive::iterators::ostream_iterator<wchar_t>(os)
92 #endif //BOOST_NO_STD_WSTRING
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));
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){
105 typedef iterators::xml_escape<const wchar_t *> xmbtows;
108 xmbtows(ws + std::wcslen(ws)),
109 boost::archive::iterators::ostream_iterator<wchar_t>(os)
114 template<class Archive>
116 xml_woarchive_impl<Archive>::xml_woarchive_impl(
120 basic_text_oprimitive<std::wostream>(
122 true // don't change the codecvt - use the one below
124 basic_xml_oarchive<Archive>(flags)
126 if(0 == (flags & no_codecvt)){
127 std::locale l = std::locale(
129 new boost::archive::detail::utf8_codecvt_facet
134 if(0 == (flags & no_header))
138 template<class Archive>
140 xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
141 if(std::uncaught_exception())
143 if(0 == (this->get_flags() & no_header)){
144 save(L"</boost_serialization>\n");
148 template<class Archive>
149 BOOST_WARCHIVE_DECL void
150 xml_woarchive_impl<Archive>::save_binary(
154 this->end_preamble();
155 #if ! defined(__MWERKS__)
156 this->basic_text_oprimitive<std::wostream>::save_binary(
158 this->basic_text_oprimitive::save_binary(
163 this->indent_next = true;
166 } // namespace archive
169 #endif //BOOST_NO_STD_WSTREAMBUF