comparison DEPENDENCIES/generic/include/boost/archive/impl/xml_wiarchive_impl.ipp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // xml_wiprimitive.cpp:
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 // See http://www.boost.org for updates, documentation, and revision history.
10
11 #include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
12
13 #include <cstring>
14 #if defined(BOOST_NO_STDC_NAMESPACE)
15 namespace std{
16 using ::memcpy;
17 } //std
18 #endif
19
20 #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
21 #ifndef BOOST_NO_STD_WSTREAMBUF
22
23 #include <boost/assert.hpp>
24 #include <algorithm>
25
26 #include <boost/detail/workaround.hpp> // Dinkumware and RogueWave
27 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
28 #include <boost/archive/dinkumware.hpp>
29 #endif
30
31 #include <boost/io/ios_state.hpp>
32 #include <boost/detail/no_exceptions_support.hpp>
33 #include <boost/serialization/pfto.hpp>
34
35 #include <boost/serialization/string.hpp>
36 #include <boost/archive/add_facet.hpp>
37 #include <boost/archive/xml_archive_exception.hpp>
38 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
39
40 #include <boost/archive/iterators/mb_from_wchar.hpp>
41
42 #include <boost/archive/basic_xml_archive.hpp>
43 #include <boost/archive/xml_wiarchive.hpp>
44
45 #include "basic_xml_grammar.hpp"
46
47 namespace boost {
48 namespace archive {
49
50 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
51 // implemenations of functions specific to wide char archives
52
53 namespace { // anonymous
54
55 void copy_to_ptr(char * s, const std::wstring & ws){
56 std::copy(
57 iterators::mb_from_wchar<std::wstring::const_iterator>(
58 BOOST_MAKE_PFTO_WRAPPER(ws.begin())
59 ),
60 iterators::mb_from_wchar<std::wstring::const_iterator>(
61 BOOST_MAKE_PFTO_WRAPPER(ws.end())
62 ),
63 s
64 );
65 s[ws.size()] = 0;
66 }
67
68 } // anonymous
69
70 template<class Archive>
71 BOOST_WARCHIVE_DECL(void)
72 xml_wiarchive_impl<Archive>::load(std::string & s){
73 std::wstring ws;
74 bool result = gimpl->parse_string(is, ws);
75 if(! result)
76 boost::serialization::throw_exception(
77 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
78 );
79 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
80 if(NULL != s.data())
81 #endif
82 s.resize(0);
83 s.reserve(ws.size());
84 std::copy(
85 iterators::mb_from_wchar<std::wstring::iterator>(
86 BOOST_MAKE_PFTO_WRAPPER(ws.begin())
87 ),
88 iterators::mb_from_wchar<std::wstring::iterator>(
89 BOOST_MAKE_PFTO_WRAPPER(ws.end())
90 ),
91 std::back_inserter(s)
92 );
93 }
94
95 #ifndef BOOST_NO_STD_WSTRING
96 template<class Archive>
97 BOOST_WARCHIVE_DECL(void)
98 xml_wiarchive_impl<Archive>::load(std::wstring & ws){
99 bool result = gimpl->parse_string(is, ws);
100 if(! result)
101 boost::serialization::throw_exception(
102 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
103 );
104 }
105 #endif
106
107 template<class Archive>
108 BOOST_WARCHIVE_DECL(void)
109 xml_wiarchive_impl<Archive>::load(char * s){
110 std::wstring ws;
111 bool result = gimpl->parse_string(is, ws);
112 if(! result)
113 boost::serialization::throw_exception(
114 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
115 );
116 copy_to_ptr(s, ws);
117 }
118
119 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
120 template<class Archive>
121 BOOST_WARCHIVE_DECL(void)
122 xml_wiarchive_impl<Archive>::load(wchar_t * ws){
123 std::wstring twstring;
124 bool result = gimpl->parse_string(is, twstring);
125 if(! result)
126 boost::serialization::throw_exception(
127 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
128 );
129 std::memcpy(ws, twstring.c_str(), twstring.size());
130 ws[twstring.size()] = L'\0';
131 }
132 #endif
133
134 template<class Archive>
135 BOOST_WARCHIVE_DECL(void)
136 xml_wiarchive_impl<Archive>::load_override(class_name_type & t, int){
137 const std::wstring & ws = gimpl->rv.class_name;
138 if(ws.size() > BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)
139 boost::serialization::throw_exception(
140 archive_exception(archive_exception::invalid_class_name)
141 );
142 copy_to_ptr(t, ws);
143 }
144
145 template<class Archive>
146 BOOST_WARCHIVE_DECL(void)
147 xml_wiarchive_impl<Archive>::init(){
148 gimpl->init(is);
149 this->set_library_version(
150 library_version_type(gimpl->rv.version)
151 );
152 }
153
154 template<class Archive>
155 BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
156 xml_wiarchive_impl<Archive>::xml_wiarchive_impl(
157 std::wistream &is_,
158 unsigned int flags
159 ) :
160 basic_text_iprimitive<std::wistream>(
161 is_,
162 true // don't change the codecvt - use the one below
163 ),
164 basic_xml_iarchive<Archive>(flags),
165 gimpl(new xml_wgrammar())
166 {
167 if(0 == (flags & no_codecvt)){
168 archive_locale.reset(
169 add_facet(
170 std::locale::classic(),
171 new boost::archive::detail::utf8_codecvt_facet
172 )
173 );
174 is.imbue(* archive_locale);
175 }
176 if(0 == (flags & no_header)){
177 BOOST_TRY{
178 this->init();
179 }
180 BOOST_CATCH(...){
181 delete gimpl;
182 #ifndef BOOST_NO_EXCEPTIONS
183 throw; // re-throw
184 #endif
185 }
186 BOOST_CATCH_END
187 }
188 }
189
190 template<class Archive>
191 BOOST_WARCHIVE_DECL(BOOST_PP_EMPTY())
192 xml_wiarchive_impl<Archive>::~xml_wiarchive_impl(){
193 if(0 == (this->get_flags() & no_header)){
194 BOOST_TRY{
195 gimpl->windup(is);
196 }
197 BOOST_CATCH(...){}
198 BOOST_CATCH_END
199 }
200 delete gimpl;
201 }
202
203 } // namespace archive
204 } // namespace boost
205
206 #endif // BOOST_NO_STD_WSTREAMBUF