Statistics
| Revision:

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

History | View | Annotate | Download (4.2 kB)

1 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 2486 sjacqu01
// xml_woarchive_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
#include <boost/config.hpp>
10 2486 sjacqu01
#ifndef BOOST_NO_STD_WSTREAMBUF
11 2486 sjacqu01
12 2486 sjacqu01
#include <ostream>
13 2486 sjacqu01
#include <string>
14 2486 sjacqu01
#include <algorithm> // std::copy
15 2486 sjacqu01
#include <locale>
16 2486 sjacqu01
17 2486 sjacqu01
#include <cstring> // strlen
18 2486 sjacqu01
#include <cstdlib> // mbtowc
19 2486 sjacqu01
#include <cwchar>  // wcslen
20 2486 sjacqu01
21 2486 sjacqu01
#include <boost/config.hpp>
22 2486 sjacqu01
#if defined(BOOST_NO_STDC_NAMESPACE)
23 2486 sjacqu01
namespace std{
24 2486 sjacqu01
    using ::strlen;
25 2486 sjacqu01
    #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
26 2486 sjacqu01
        using ::mbtowc;
27 2486 sjacqu01
        using ::wcslen;
28 2486 sjacqu01
    #endif
29 2486 sjacqu01
} // namespace std
30 2486 sjacqu01
#endif
31 2486 sjacqu01
32 2486 sjacqu01
#include <boost/archive/xml_woarchive.hpp>
33 2486 sjacqu01
#include <boost/serialization/throw_exception.hpp>
34 2486 sjacqu01
35 2486 sjacqu01
#include <boost/archive/iterators/xml_escape.hpp>
36 2486 sjacqu01
#include <boost/archive/iterators/wchar_from_mb.hpp>
37 2486 sjacqu01
#include <boost/archive/iterators/ostream_iterator.hpp>
38 2486 sjacqu01
#include <boost/archive/iterators/dataflow_exception.hpp>
39 2486 sjacqu01
40 2486 sjacqu01
#include <boost/archive/add_facet.hpp>
41 2486 sjacqu01
42 2486 sjacqu01
namespace boost {
43 2486 sjacqu01
namespace archive {
44 2486 sjacqu01
45 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
46 2486 sjacqu01
// implemenations of functions specific to wide char archives
47 2486 sjacqu01
48 2486 sjacqu01
// copy chars to output escaping to xml and widening characters as we go
49 2486 sjacqu01
template<class InputIterator>
50 2486 sjacqu01
void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){
51 2486 sjacqu01
    typedef iterators::wchar_from_mb<
52 2486 sjacqu01
        iterators::xml_escape<InputIterator>
53 2486 sjacqu01
    > xmbtows;
54 2486 sjacqu01
    std::copy(
55 2486 sjacqu01
        xmbtows(begin),
56 2486 sjacqu01
        xmbtows(end),
57 2486 sjacqu01
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
58 2486 sjacqu01
    );
59 2486 sjacqu01
}
60 2486 sjacqu01
61 2486 sjacqu01
template<class Archive>
62 2486 sjacqu01
BOOST_WARCHIVE_DECL void
63 2486 sjacqu01
xml_woarchive_impl<Archive>::save(const std::string & s){
64 2486 sjacqu01
    // note: we don't use s.begin() and s.end() because dinkumware
65 2486 sjacqu01
    // doesn't have string::value_type defined. So use a wrapper
66 2486 sjacqu01
    // around these values to implement the definitions.
67 2486 sjacqu01
    const char * begin = s.data();
68 2486 sjacqu01
    const char * end = begin + s.size();
69 2486 sjacqu01
    save_iterator(os, begin, end);
70 2486 sjacqu01
}
71 2486 sjacqu01
72 2486 sjacqu01
#ifndef BOOST_NO_STD_WSTRING
73 2486 sjacqu01
template<class Archive>
74 2486 sjacqu01
BOOST_WARCHIVE_DECL void
75 2486 sjacqu01
xml_woarchive_impl<Archive>::save(const std::wstring & ws){
76 2486 sjacqu01
#if 0
77 2486 sjacqu01
    typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
78 2486 sjacqu01
    std::copy(
79 2486 sjacqu01
        xmbtows(ws.begin()),
80 2486 sjacqu01
        xmbtows(ws.end()),
81 2486 sjacqu01
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
82 2486 sjacqu01
    );
83 2486 sjacqu01
#endif
84 2486 sjacqu01
    typedef iterators::xml_escape<const wchar_t *> xmbtows;
85 2486 sjacqu01
    std::copy(
86 2486 sjacqu01
        xmbtows(ws.data()),
87 2486 sjacqu01
        xmbtows(ws.data() + ws.size()),
88 2486 sjacqu01
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
89 2486 sjacqu01
    );
90 2486 sjacqu01
}
91 2486 sjacqu01
#endif //BOOST_NO_STD_WSTRING
92 2486 sjacqu01
93 2486 sjacqu01
template<class Archive>
94 2486 sjacqu01
BOOST_WARCHIVE_DECL void
95 2486 sjacqu01
xml_woarchive_impl<Archive>::save(const char * s){
96 2486 sjacqu01
   save_iterator(os, s, s + std::strlen(s));
97 2486 sjacqu01
}
98 2486 sjacqu01
99 2486 sjacqu01
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
100 2486 sjacqu01
template<class Archive>
101 2486 sjacqu01
BOOST_WARCHIVE_DECL void
102 2486 sjacqu01
xml_woarchive_impl<Archive>::save(const wchar_t * ws){
103 2486 sjacqu01
    os << ws;
104 2486 sjacqu01
    typedef iterators::xml_escape<const wchar_t *> xmbtows;
105 2486 sjacqu01
    std::copy(
106 2486 sjacqu01
        xmbtows(ws),
107 2486 sjacqu01
        xmbtows(ws + std::wcslen(ws)),
108 2486 sjacqu01
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
109 2486 sjacqu01
    );
110 2486 sjacqu01
}
111 2486 sjacqu01
#endif
112 2486 sjacqu01
113 2486 sjacqu01
template<class Archive>
114 2486 sjacqu01
BOOST_WARCHIVE_DECL
115 2486 sjacqu01
xml_woarchive_impl<Archive>::xml_woarchive_impl(
116 2486 sjacqu01
    std::wostream & os_,
117 2486 sjacqu01
    unsigned int flags
118 2486 sjacqu01
) :
119 2486 sjacqu01
    basic_text_oprimitive<std::wostream>(
120 2486 sjacqu01
        os_,
121 2486 sjacqu01
        true // don't change the codecvt - use the one below
122 2486 sjacqu01
    ),
123 2486 sjacqu01
    basic_xml_oarchive<Archive>(flags)
124 2486 sjacqu01
{
125 2486 sjacqu01
    // Standard behavior is that imbue can be called
126 2486 sjacqu01
    // a) before output is invoked or
127 2486 sjacqu01
    // b) after flush has been called.  This prevents one-to-many
128 2486 sjacqu01
    // transforms (such as one to many transforms from getting
129 2486 sjacqu01
    // mixed up.
130 2486 sjacqu01
    if(0 == (flags & no_codecvt)){
131 2486 sjacqu01
        archive_locale.reset(
132 2486 sjacqu01
            add_facet(
133 2486 sjacqu01
                os_.getloc(),
134 2486 sjacqu01
                new boost::archive::detail::utf8_codecvt_facet
135 2486 sjacqu01
            )
136 2486 sjacqu01
        );
137 2486 sjacqu01
        //os.imbue(* archive_locale);
138 2486 sjacqu01
    }
139 2486 sjacqu01
    if(0 == (flags & no_header))
140 2486 sjacqu01
        this->init();
141 2486 sjacqu01
}
142 2486 sjacqu01
143 2486 sjacqu01
template<class Archive>
144 2486 sjacqu01
BOOST_WARCHIVE_DECL
145 2486 sjacqu01
xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
146 2486 sjacqu01
}
147 2486 sjacqu01
148 2486 sjacqu01
} // namespace archive
149 2486 sjacqu01
} // namespace boost
150 2486 sjacqu01
151 2486 sjacqu01
#endif //BOOST_NO_STD_WSTREAMBUF