File indexing completed on 2025-01-18 09:28:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <cstring>
0012 #if defined(BOOST_NO_STDC_NAMESPACE)
0013 namespace std{
0014 using ::memcpy;
0015 }
0016 #endif
0017
0018 #include <boost/config.hpp> // msvc 6.0 needs this to suppress warnings
0019 #ifndef BOOST_NO_STD_WSTREAMBUF
0020
0021 #include <boost/assert.hpp>
0022 #include <algorithm> // std::copy
0023 #include <boost/detail/workaround.hpp> // Dinkumware and RogueWave
0024 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
0025 #include <boost/archive/dinkumware.hpp>
0026 #endif
0027
0028 #include <boost/io/ios_state.hpp>
0029 #include <boost/core/uncaught_exceptions.hpp>
0030 #include <boost/core/no_exceptions_support.hpp>
0031 #include <boost/serialization/string.hpp>
0032
0033 #include <boost/archive/basic_xml_archive.hpp>
0034 #include <boost/archive/xml_wiarchive.hpp>
0035
0036 #include <boost/archive/xml_archive_exception.hpp>
0037 #include <boost/archive/iterators/mb_from_wchar.hpp>
0038
0039 #include <boost/archive/detail/utf8_codecvt_facet.hpp>
0040
0041 #include "basic_xml_grammar.hpp"
0042
0043 namespace boost {
0044 namespace archive {
0045
0046
0047
0048
0049 namespace {
0050
0051 void copy_to_ptr(char * s, const std::wstring & ws){
0052 std::copy(
0053 iterators::mb_from_wchar<std::wstring::const_iterator>(
0054 ws.begin()
0055 ),
0056 iterators::mb_from_wchar<std::wstring::const_iterator>(
0057 ws.end()
0058 ),
0059 s
0060 );
0061 s[ws.size()] = 0;
0062 }
0063
0064 }
0065
0066 template<class Archive>
0067 BOOST_WARCHIVE_DECL void
0068 xml_wiarchive_impl<Archive>::load(std::string & s){
0069 std::wstring ws;
0070 bool result = gimpl->parse_string(is, ws);
0071 if(! result)
0072 boost::serialization::throw_exception(
0073 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
0074 );
0075 #if BOOST_WORKAROUND(_RWSTD_VER, BOOST_TESTED_AT(20101))
0076 if(NULL != s.data())
0077 #endif
0078 s.resize(0);
0079 s.reserve(ws.size());
0080 std::copy(
0081 iterators::mb_from_wchar<std::wstring::iterator>(
0082 ws.begin()
0083 ),
0084 iterators::mb_from_wchar<std::wstring::iterator>(
0085 ws.end()
0086 ),
0087 std::back_inserter(s)
0088 );
0089 }
0090
0091 #ifndef BOOST_NO_STD_WSTRING
0092 template<class Archive>
0093 BOOST_WARCHIVE_DECL void
0094 xml_wiarchive_impl<Archive>::load(std::wstring & ws){
0095 bool result = gimpl->parse_string(is, ws);
0096 if(! result)
0097 boost::serialization::throw_exception(
0098 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
0099 );
0100 }
0101 #endif
0102
0103 template<class Archive>
0104 BOOST_WARCHIVE_DECL void
0105 xml_wiarchive_impl<Archive>::load(char * s){
0106 std::wstring ws;
0107 bool result = gimpl->parse_string(is, ws);
0108 if(! result)
0109 boost::serialization::throw_exception(
0110 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
0111 );
0112 copy_to_ptr(s, ws);
0113 }
0114
0115 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
0116 template<class Archive>
0117 BOOST_WARCHIVE_DECL void
0118 xml_wiarchive_impl<Archive>::load(wchar_t * ws){
0119 std::wstring twstring;
0120 bool result = gimpl->parse_string(is, twstring);
0121 if(! result)
0122 boost::serialization::throw_exception(
0123 xml_archive_exception(xml_archive_exception::xml_archive_parsing_error)
0124 );
0125 std::memcpy(ws, twstring.c_str(), twstring.size());
0126 ws[twstring.size()] = L'\0';
0127 }
0128 #endif
0129
0130 template<class Archive>
0131 BOOST_WARCHIVE_DECL void
0132 xml_wiarchive_impl<Archive>::load_override(class_name_type & t){
0133 const std::wstring & ws = gimpl->rv.class_name;
0134 if(ws.size() > BOOST_SERIALIZATION_MAX_KEY_SIZE - 1)
0135 boost::serialization::throw_exception(
0136 archive_exception(archive_exception::invalid_class_name)
0137 );
0138 copy_to_ptr(t, ws);
0139 }
0140
0141 template<class Archive>
0142 BOOST_WARCHIVE_DECL void
0143 xml_wiarchive_impl<Archive>::init(){
0144 gimpl->init(is);
0145 this->set_library_version(
0146 boost::serialization::library_version_type(gimpl->rv.version)
0147 );
0148 }
0149
0150 template<class Archive>
0151 BOOST_WARCHIVE_DECL
0152 xml_wiarchive_impl<Archive>::xml_wiarchive_impl(
0153 std::wistream &is_,
0154 unsigned int flags
0155 ) :
0156 basic_text_iprimitive<std::wistream>(
0157 is_,
0158 true
0159 ),
0160 basic_xml_iarchive<Archive>(flags),
0161 gimpl(new xml_wgrammar())
0162 {
0163 if(0 == (flags & no_codecvt)){
0164 archive_locale = std::locale(
0165 is_.getloc(),
0166 new boost::archive::detail::utf8_codecvt_facet
0167 );
0168
0169 is_.sync();
0170 is_.imbue(archive_locale);
0171 }
0172 }
0173
0174 template<class Archive>
0175 BOOST_WARCHIVE_DECL
0176 xml_wiarchive_impl<Archive>::~xml_wiarchive_impl(){
0177 if(boost::core::uncaught_exceptions() > 0)
0178 return;
0179 if(0 == (this->get_flags() & no_header)){
0180 gimpl->windup(is);
0181 }
0182 }
0183
0184 }
0185 }
0186
0187 #endif