Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / archive / iterators / wchar_from_mb.hpp @ 2486

History | View | Annotate | Download (3.2 kB)

1
#ifndef BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP
2
#define BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP
3

    
4
// MS compatible compilers support #pragma once
5
#if defined(_MSC_VER)
6
# pragma once
7
#endif
8

    
9
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10
// wchar_from_mb.hpp
11

    
12
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 
13
// Use, modification and distribution is subject to the Boost Software
14
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15
// http://www.boost.org/LICENSE_1_0.txt)
16

    
17
//  See http://www.boost.org for updates, documentation, and revision history.
18

    
19
#include <boost/assert.hpp>
20
#include <cctype>
21
#include <cstddef> // size_t
22
#include <cwchar> // mbstate_t and mbrtowc
23

    
24
#include <boost/config.hpp>
25
#if defined(BOOST_NO_STDC_NAMESPACE)
26
namespace std{ 
27
    using ::mbstate_t;
28
    using ::mbrtowc;
29
} // namespace std
30
#endif
31

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

    
34
#include <boost/iterator/iterator_adaptor.hpp>
35
#include <boost/archive/iterators/dataflow_exception.hpp>
36

    
37
namespace boost { 
38
namespace archive {
39
namespace iterators {
40

    
41
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
42
// class used by text archives to translate char strings to wchar_t
43
// strings of the currently selected locale
44
template<class Base>
45
class wchar_from_mb 
46
    : public boost::iterator_adaptor<
47
        wchar_from_mb<Base>, 
48
        Base, 
49
        wchar_t,
50
        single_pass_traversal_tag,
51
        wchar_t
52
    >
53
{
54
    friend class boost::iterator_core_access;
55
    typedef typename boost::iterator_adaptor<
56
        wchar_from_mb<Base>, 
57
        Base, 
58
        wchar_t,
59
        single_pass_traversal_tag,
60
        wchar_t
61
    > super_t;
62

    
63
    typedef wchar_from_mb<Base> this_t;
64

    
65
    wchar_t drain();
66

    
67
    wchar_t dereference_impl() {
68
        if(! m_full){
69
            m_current_value = drain();
70
            m_full = true;
71
        }
72
        return m_current_value;
73
    }
74

    
75
    wchar_t dereference() const {
76
        return const_cast<this_t *>(this)->dereference_impl();
77
    }
78

    
79
    void increment(){
80
        dereference_impl();
81
        m_full = false;
82
        ++(this->base_reference());
83
    };
84

    
85
    wchar_t m_current_value;
86
    bool m_full;
87

    
88
public:
89
    // make composible buy using templated constructor
90
    template<class T>
91
    wchar_from_mb(T start) : 
92
        super_t(Base(static_cast< T >(start))),
93
        m_full(false)
94
    {}
95
    // intel 7.1 doesn't like default copy constructor
96
    wchar_from_mb(const wchar_from_mb & rhs) : 
97
        super_t(rhs.base_reference()),
98
        m_full(rhs.m_full)
99
    {}
100
};
101

    
102
template<class Base>
103
wchar_t wchar_from_mb<Base>::drain(){
104
    std::mbstate_t mbs;
105
    wchar_t retval;
106
    std::size_t result;
107
    do {
108
        char val = *this->base_reference();
109
        result = std::mbrtowc(&retval, &val, 1, &mbs);
110
        if(result == static_cast<std::size_t>(-1))
111
            boost::serialization::throw_exception(iterators::dataflow_exception(
112
                iterators::dataflow_exception::invalid_conversion
113
            ));
114
    } while (result == static_cast<std::size_t>(-2));
115
    return retval;
116
}
117

    
118
} // namespace iterators
119
} // namespace archive
120
} // namespace boost
121

    
122
#endif // BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP