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
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2
// xml_woarchive_impl.ipp:
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
#include <boost/config.hpp>
10
#ifndef BOOST_NO_STD_WSTREAMBUF
11

    
12
#include <ostream>
13
#include <string>
14
#include <algorithm> // std::copy
15
#include <locale>
16

    
17
#include <cstring> // strlen
18
#include <cstdlib> // mbtowc
19
#include <cwchar>  // wcslen
20

    
21
#include <boost/config.hpp>
22
#if defined(BOOST_NO_STDC_NAMESPACE)
23
namespace std{ 
24
    using ::strlen; 
25
    #if ! defined(BOOST_NO_INTRINSIC_WCHAR_T)
26
        using ::mbtowc; 
27
        using ::wcslen;
28
    #endif
29
} // namespace std
30
#endif
31

    
32
#include <boost/archive/xml_woarchive.hpp>
33
#include <boost/serialization/throw_exception.hpp>
34

    
35
#include <boost/archive/iterators/xml_escape.hpp>
36
#include <boost/archive/iterators/wchar_from_mb.hpp>
37
#include <boost/archive/iterators/ostream_iterator.hpp>
38
#include <boost/archive/iterators/dataflow_exception.hpp>
39

    
40
#include <boost/archive/add_facet.hpp>
41

    
42
namespace boost {
43
namespace archive {
44

    
45
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
46
// implemenations of functions specific to wide char archives
47

    
48
// copy chars to output escaping to xml and widening characters as we go
49
template<class InputIterator>
50
void save_iterator(std::wostream &os, InputIterator begin, InputIterator end){
51
    typedef iterators::wchar_from_mb<
52
        iterators::xml_escape<InputIterator>
53
    > xmbtows;
54
    std::copy(
55
        xmbtows(begin),
56
        xmbtows(end),
57
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
58
    );
59
}
60

    
61
template<class Archive>
62
BOOST_WARCHIVE_DECL void
63
xml_woarchive_impl<Archive>::save(const std::string & s){
64
    // note: we don't use s.begin() and s.end() because dinkumware
65
    // doesn't have string::value_type defined. So use a wrapper
66
    // around these values to implement the definitions.
67
    const char * begin = s.data();
68
    const char * end = begin + s.size();
69
    save_iterator(os, begin, end);
70
}
71

    
72
#ifndef BOOST_NO_STD_WSTRING
73
template<class Archive>
74
BOOST_WARCHIVE_DECL void
75
xml_woarchive_impl<Archive>::save(const std::wstring & ws){
76
#if 0
77
    typedef iterators::xml_escape<std::wstring::const_iterator> xmbtows;
78
    std::copy(
79
        xmbtows(ws.begin()),
80
        xmbtows(ws.end()),
81
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
82
    );
83
#endif
84
    typedef iterators::xml_escape<const wchar_t *> xmbtows;
85
    std::copy(
86
        xmbtows(ws.data()),
87
        xmbtows(ws.data() + ws.size()),
88
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
89
    );
90
}
91
#endif //BOOST_NO_STD_WSTRING
92

    
93
template<class Archive>
94
BOOST_WARCHIVE_DECL void
95
xml_woarchive_impl<Archive>::save(const char * s){
96
   save_iterator(os, s, s + std::strlen(s));
97
}
98

    
99
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
100
template<class Archive>
101
BOOST_WARCHIVE_DECL void
102
xml_woarchive_impl<Archive>::save(const wchar_t * ws){
103
    os << ws;
104
    typedef iterators::xml_escape<const wchar_t *> xmbtows;
105
    std::copy(
106
        xmbtows(ws),
107
        xmbtows(ws + std::wcslen(ws)),
108
        boost::archive::iterators::ostream_iterator<wchar_t>(os)
109
    );
110
}
111
#endif
112

    
113
template<class Archive>
114
BOOST_WARCHIVE_DECL
115
xml_woarchive_impl<Archive>::xml_woarchive_impl(
116
    std::wostream & os_,
117
    unsigned int flags
118
) :
119
    basic_text_oprimitive<std::wostream>(
120
        os_,
121
        true // don't change the codecvt - use the one below
122
    ),
123
    basic_xml_oarchive<Archive>(flags)
124
{
125
    // Standard behavior is that imbue can be called
126
    // a) before output is invoked or
127
    // b) after flush has been called.  This prevents one-to-many
128
    // transforms (such as one to many transforms from getting
129
    // mixed up.
130
    if(0 == (flags & no_codecvt)){
131
        archive_locale.reset(
132
            add_facet(
133
                os_.getloc(),
134
                new boost::archive::detail::utf8_codecvt_facet
135
            )
136
        );
137
        //os.imbue(* archive_locale);
138
    }
139
    if(0 == (flags & no_header))
140
        this->init();
141
}
142

    
143
template<class Archive>
144
BOOST_WARCHIVE_DECL
145
xml_woarchive_impl<Archive>::~xml_woarchive_impl(){
146
}
147

    
148
} // namespace archive
149
} // namespace boost
150

    
151
#endif //BOOST_NO_STD_WSTREAMBUF