Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / impl / xml_wiarchive_impl.ipp @ 2486

History | View | Annotate | Download (5.2 kB)

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