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 2486 sjacqu01
#ifndef BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP
2 2486 sjacqu01
#define BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP
3 2486 sjacqu01
4 2486 sjacqu01
// MS compatible compilers support #pragma once
5 2486 sjacqu01
#if defined(_MSC_VER)
6 2486 sjacqu01
# pragma once
7 2486 sjacqu01
#endif
8 2486 sjacqu01
9 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 2486 sjacqu01
// wchar_from_mb.hpp
11 2486 sjacqu01
12 2486 sjacqu01
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 2486 sjacqu01
// Use, modification and distribution is subject to the Boost Software
14 2486 sjacqu01
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 2486 sjacqu01
// http://www.boost.org/LICENSE_1_0.txt)
16 2486 sjacqu01
17 2486 sjacqu01
//  See http://www.boost.org for updates, documentation, and revision history.
18 2486 sjacqu01
19 2486 sjacqu01
#include <boost/assert.hpp>
20 2486 sjacqu01
#include <cctype>
21 2486 sjacqu01
#include <cstddef> // size_t
22 2486 sjacqu01
#include <cwchar> // mbstate_t and mbrtowc
23 2486 sjacqu01
24 2486 sjacqu01
#include <boost/config.hpp>
25 2486 sjacqu01
#if defined(BOOST_NO_STDC_NAMESPACE)
26 2486 sjacqu01
namespace std{
27 2486 sjacqu01
    using ::mbstate_t;
28 2486 sjacqu01
    using ::mbrtowc;
29 2486 sjacqu01
} // namespace std
30 2486 sjacqu01
#endif
31 2486 sjacqu01
32 2486 sjacqu01
#include <boost/serialization/throw_exception.hpp>
33 2486 sjacqu01
34 2486 sjacqu01
#include <boost/iterator/iterator_adaptor.hpp>
35 2486 sjacqu01
#include <boost/archive/iterators/dataflow_exception.hpp>
36 2486 sjacqu01
37 2486 sjacqu01
namespace boost {
38 2486 sjacqu01
namespace archive {
39 2486 sjacqu01
namespace iterators {
40 2486 sjacqu01
41 2486 sjacqu01
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
42 2486 sjacqu01
// class used by text archives to translate char strings to wchar_t
43 2486 sjacqu01
// strings of the currently selected locale
44 2486 sjacqu01
template<class Base>
45 2486 sjacqu01
class wchar_from_mb
46 2486 sjacqu01
    : public boost::iterator_adaptor<
47 2486 sjacqu01
        wchar_from_mb<Base>,
48 2486 sjacqu01
        Base,
49 2486 sjacqu01
        wchar_t,
50 2486 sjacqu01
        single_pass_traversal_tag,
51 2486 sjacqu01
        wchar_t
52 2486 sjacqu01
    >
53 2486 sjacqu01
{
54 2486 sjacqu01
    friend class boost::iterator_core_access;
55 2486 sjacqu01
    typedef typename boost::iterator_adaptor<
56 2486 sjacqu01
        wchar_from_mb<Base>,
57 2486 sjacqu01
        Base,
58 2486 sjacqu01
        wchar_t,
59 2486 sjacqu01
        single_pass_traversal_tag,
60 2486 sjacqu01
        wchar_t
61 2486 sjacqu01
    > super_t;
62 2486 sjacqu01
63 2486 sjacqu01
    typedef wchar_from_mb<Base> this_t;
64 2486 sjacqu01
65 2486 sjacqu01
    wchar_t drain();
66 2486 sjacqu01
67 2486 sjacqu01
    wchar_t dereference_impl() {
68 2486 sjacqu01
        if(! m_full){
69 2486 sjacqu01
            m_current_value = drain();
70 2486 sjacqu01
            m_full = true;
71 2486 sjacqu01
        }
72 2486 sjacqu01
        return m_current_value;
73 2486 sjacqu01
    }
74 2486 sjacqu01
75 2486 sjacqu01
    wchar_t dereference() const {
76 2486 sjacqu01
        return const_cast<this_t *>(this)->dereference_impl();
77 2486 sjacqu01
    }
78 2486 sjacqu01
79 2486 sjacqu01
    void increment(){
80 2486 sjacqu01
        dereference_impl();
81 2486 sjacqu01
        m_full = false;
82 2486 sjacqu01
        ++(this->base_reference());
83 2486 sjacqu01
    };
84 2486 sjacqu01
85 2486 sjacqu01
    wchar_t m_current_value;
86 2486 sjacqu01
    bool m_full;
87 2486 sjacqu01
88 2486 sjacqu01
public:
89 2486 sjacqu01
    // make composible buy using templated constructor
90 2486 sjacqu01
    template<class T>
91 2486 sjacqu01
    wchar_from_mb(T start) :
92 2486 sjacqu01
        super_t(Base(static_cast< T >(start))),
93 2486 sjacqu01
        m_full(false)
94 2486 sjacqu01
    {}
95 2486 sjacqu01
    // intel 7.1 doesn't like default copy constructor
96 2486 sjacqu01
    wchar_from_mb(const wchar_from_mb & rhs) :
97 2486 sjacqu01
        super_t(rhs.base_reference()),
98 2486 sjacqu01
        m_full(rhs.m_full)
99 2486 sjacqu01
    {}
100 2486 sjacqu01
};
101 2486 sjacqu01
102 2486 sjacqu01
template<class Base>
103 2486 sjacqu01
wchar_t wchar_from_mb<Base>::drain(){
104 2486 sjacqu01
    std::mbstate_t mbs;
105 2486 sjacqu01
    wchar_t retval;
106 2486 sjacqu01
    std::size_t result;
107 2486 sjacqu01
    do {
108 2486 sjacqu01
        char val = *this->base_reference();
109 2486 sjacqu01
        result = std::mbrtowc(&retval, &val, 1, &mbs);
110 2486 sjacqu01
        if(result == static_cast<std::size_t>(-1))
111 2486 sjacqu01
            boost::serialization::throw_exception(iterators::dataflow_exception(
112 2486 sjacqu01
                iterators::dataflow_exception::invalid_conversion
113 2486 sjacqu01
            ));
114 2486 sjacqu01
    } while (result == static_cast<std::size_t>(-2));
115 2486 sjacqu01
    return retval;
116 2486 sjacqu01
}
117 2486 sjacqu01
118 2486 sjacqu01
} // namespace iterators
119 2486 sjacqu01
} // namespace archive
120 2486 sjacqu01
} // namespace boost
121 2486 sjacqu01
122 2486 sjacqu01
#endif // BOOST_ARCHIVE_ITERATORS_WCHAR_FROM_MB_HPP