1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // xml_wiarchive_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 // See http://www.boost.org for updates, documentation, and revision history.
12 #if defined(BOOST_NO_STDC_NAMESPACE)
18 #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
19 #ifndef BOOST_NO_STD_WSTREAMBUF
21 #include <boost/assert.hpp>
22 #include <algorithm> // std::copy
23 #include <exception> // uncaught exception
24 #include <boost/detail/workaround.hpp> // Dinkumware and RogueWave
25 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
26 #include <boost/archive/dinkumware.hpp>
29 #include <boost/io/ios_state.hpp>
30 #include <boost/core/no_exceptions_support.hpp>
31 #include <boost/serialization/string.hpp>
33 #include <boost/archive/basic_xml_archive.hpp>
34 #include <boost/archive/xml_wiarchive.hpp>
36 #include <boost/archive/xml_archive_exception.hpp>
37 #include <boost/archive/iterators/mb_from_wchar.hpp>
39 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
41 #include "basic_xml_grammar.hpp"
46 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
47 // implemenations of functions specific to wide char archives
49 namespace { // anonymous
51 void copy_to_ptr(char * s, const std::wstring & ws){
53 iterators::mb_from_wchar<std::wstring::const_iterator>(
56 iterators::mb_from_wchar<std::wstring::const_iterator>(
66 template<class Archive>
67 BOOST_WARCHIVE_DECL void
68 xml_wiarchive_impl<Archive>::load(std::string & s){
70 bool result = gimpl->parse_string(is, ws);
72 boost::serialization::throw_exception(
73 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
75 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
81 iterators::mb_from_wchar<std::wstring::iterator>(
84 iterators::mb_from_wchar<std::wstring::iterator>(
91 #ifndef BOOST_NO_STD_WSTRING
92 template<class Archive>
93 BOOST_WARCHIVE_DECL void
94 xml_wiarchive_impl<Archive>::load(std::wstring & ws){
95 bool result = gimpl->parse_string(is, ws);
97 boost::serialization::throw_exception(
98 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
103 template<class Archive>
104 BOOST_WARCHIVE_DECL void
105 xml_wiarchive_impl<Archive>::load(char * s){
107 bool result = gimpl->parse_string(is, ws);
109 boost::serialization::throw_exception(
110 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
115 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
116 template<class Archive>
117 BOOST_WARCHIVE_DECL void
118 xml_wiarchive_impl<Archive>::load(wchar_t * ws){
119 std::wstring twstring;
120 bool result = gimpl->parse_string(is, twstring);
122 boost::serialization::throw_exception(
123 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
125 std::memcpy(ws, twstring.c_str(), twstring.size());
126 ws[twstring.size()] = L'\0';
130 template<class Archive>
131 BOOST_WARCHIVE_DECL void
132 xml_wiarchive_impl<Archive>::load_override(class_name_type & t){
133 const std::wstring & ws = gimpl->rv.class_name;
134 if(ws.size() > BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)
135 boost::serialization::throw_exception(
136 archive_exception(archive_exception::invalid_class_name)
141 template<class Archive>
142 BOOST_WARCHIVE_DECL void
143 xml_wiarchive_impl<Archive>::init(){
145 this->set_library_version(
146 library_version_type(gimpl->rv.version)
150 template<class Archive>
152 xml_wiarchive_impl<Archive>::xml_wiarchive_impl(
156 basic_text_iprimitive<std::wistream>(
158 true // don't change the codecvt - use the one below
160 basic_xml_iarchive<Archive>(flags),
161 gimpl(new xml_wgrammar())
163 if(0 == (flags & no_codecvt)){
164 archive_locale = std::locale(
166 new boost::archive::detail::utf8_codecvt_facet
168 // libstdc++ crashes without this
170 is_.imbue(archive_locale);
172 if(0 == (flags & no_header))
176 template<class Archive>
178 xml_wiarchive_impl<Archive>::~xml_wiarchive_impl(){
179 if(std::uncaught_exception())
181 if(0 == (this->get_flags() & no_header)){
186 } // namespace archive
189 #endif // BOOST_NO_STD_WSTREAMBUF