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
17 #include <cstring> // strlen
18 #include <cstdlib> // mbtowc
19 #ifndef BOOST_NO_CWCHAR
20 #include <cwchar> // wcslen
23 #include <boost/config.hpp>
24 #if defined(BOOST_NO_STDC_NAMESPACE)
27 #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
34 #include <boost/core/uncaught_exceptions.hpp>
36 #include <boost/archive/xml_woarchive.hpp>
37 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
39 #include <boost/serialization/throw_exception.hpp>
41 #include <boost/archive/iterators/xml_escape.hpp>
42 #include <boost/archive/iterators/wchar_from_mb.hpp>
43 #include <boost/archive/iterators/ostream_iterator.hpp>
44 #include <boost/archive/iterators/dataflow_exception.hpp>
49 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
50 // implemenations of functions specific to wide char archives
52 // copy chars to output escaping to xml and widening characters as we go
53 template<class InputIterator>
54 void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){
55 typedef iterators::wchar_from_mb<
56 iterators::xml_escape<InputIterator>
61 boost::archive::iterators::ostream_iterator<wchar_t>(os)
65 template<class Archive>
66 BOOST_WARCHIVE_DECL void
67 xml_woarchive_impl<Archive>::save(const std::string & s){
68 // note: we don't use s.begin() and s.end() because dinkumware
69 // doesn't have string::value_type defined. So use a wrapper
70 // around these values to implement the definitions.
71 const char * begin = s.data();
72 const char * end = begin + s.size();
73 save_iterator(os, begin, end);
76 #ifndef BOOST_NO_STD_WSTRING
77 template<class Archive>
78 BOOST_WARCHIVE_DECL void
79 xml_woarchive_impl<Archive>::save(const std::wstring & ws){
81 typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
85 boost::archive::iterators::ostream_iterator<wchar_t>(os)
88 typedef iterators::xml_escape<const wchar_t *> xmbtows;
91 xmbtows(ws.data() + ws.size()),
92 boost::archive::iterators::ostream_iterator<wchar_t>(os)
95 #endif //BOOST_NO_STD_WSTRING
97 template<class Archive>
98 BOOST_WARCHIVE_DECL void
99 xml_woarchive_impl<Archive>::save(const char * s){
100 save_iterator(os, s, s + std::strlen(s));
103 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
104 template<class Archive>
105 BOOST_WARCHIVE_DECL void
106 xml_woarchive_impl<Archive>::save(const wchar_t * ws){
107 typedef iterators::xml_escape<const wchar_t *> xmbtows;
110 xmbtows(ws + std::wcslen(ws)),
111 boost::archive::iterators::ostream_iterator<wchar_t>(os)
116 template<class Archive>
118 xml_woarchive_impl<Archive>::xml_woarchive_impl(
122 basic_text_oprimitive<std::wostream>(
124 true // don't change the codecvt - use the one below
126 basic_xml_oarchive<Archive>(flags)
128 if(0 == (flags & no_codecvt)){
129 archive_locale = std::locale(
131 new boost::archive::detail::utf8_codecvt_facet
134 os_.imbue(archive_locale);
136 if(0 == (flags & no_header))
140 template<class Archive>
142 xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
143 if(boost::core::uncaught_exceptions() > 0)
145 if(0 == (this->get_flags() & no_header)){
146 os << L"</boost_serialization>";
150 template<class Archive>
151 BOOST_WARCHIVE_DECL void
152 xml_woarchive_impl<Archive>::save_binary(
156 this->end_preamble();
157 #if ! defined(__MWERKS__)
158 this->basic_text_oprimitive<std::wostream>::save_binary(
160 this->basic_text_oprimitive::save_binary(
165 this->indent_next = true;
168 } // namespace archive
171 #endif //BOOST_NO_STD_WSTREAMBUF