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 #ifndef BOOST_NO_CWCHAR
21 #include <cwchar> // wcslen
24 #include <boost/config.hpp>
25 #if defined(BOOST_NO_STDC_NAMESPACE)
28 #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
35 #include <boost/archive/xml_woarchive.hpp>
36 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
38 #include <boost/serialization/throw_exception.hpp>
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>
48 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
49 // implemenations of functions specific to wide char archives
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>
60 boost::archive::iterators::ostream_iterator<wchar_t>(os)
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);
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){
80 typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
84 boost::archive::iterators::ostream_iterator<wchar_t>(os)
87 typedef iterators::xml_escape<const wchar_t *> xmbtows;
90 xmbtows(ws.data() + ws.size()),
91 boost::archive::iterators::ostream_iterator<wchar_t>(os)
94 #endif //BOOST_NO_STD_WSTRING
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));
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;
109 xmbtows(ws + std::wcslen(ws)),
110 boost::archive::iterators::ostream_iterator<wchar_t>(os)
115 template<class Archive>
117 xml_woarchive_impl<Archive>::xml_woarchive_impl(
121 basic_text_oprimitive<std::wostream>(
123 true // don't change the codecvt - use the one below
125 basic_xml_oarchive<Archive>(flags)
127 if(0 == (flags & no_codecvt)){
128 archive_locale = std::locale(
130 new boost::archive::detail::utf8_codecvt_facet
133 os_.imbue(archive_locale);
135 if(0 == (flags & no_header))
139 template<class Archive>
141 xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
142 if(std::uncaught_exception())
144 if(0 == (this->get_flags() & no_header)){
145 os << L"</boost_serialization>";
149 template<class Archive>
150 BOOST_WARCHIVE_DECL void
151 xml_woarchive_impl<Archive>::save_binary(
155 this->end_preamble();
156 #if ! defined(__MWERKS__)
157 this->basic_text_oprimitive<std::wostream>::save_binary(
159 this->basic_text_oprimitive::save_binary(
164 this->indent_next = true;
167 } // namespace archive
170 #endif //BOOST_NO_STD_WSTREAMBUF