1 | // (C) Copyright Jonathan Turkanis 2003.
|
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
---|
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
|
---|
4 |
|
---|
5 | // See http://www.boost.org/libs/iostreams for documentation.
|
---|
6 |
|
---|
7 | #ifndef BOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED
|
---|
8 | #define BOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED
|
---|
9 |
|
---|
10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
11 | # pragma once
|
---|
12 | #endif
|
---|
13 |
|
---|
14 | #include <boost/type_traits/is_same.hpp>
|
---|
15 |
|
---|
16 | namespace boost { namespace iostreams { namespace detail {
|
---|
17 |
|
---|
18 | template<bool IsSame>
|
---|
19 | struct translate_int_type_impl;
|
---|
20 |
|
---|
21 | //
|
---|
22 | // Template name: translate_char.
|
---|
23 | // Description: Translates a character or an end-of-file indicator from the
|
---|
24 | // int_type of one character traits type to the int_type of another.
|
---|
25 | //
|
---|
26 | template<typename SourceTr, typename TargetTr>
|
---|
27 | typename TargetTr::int_type
|
---|
28 | translate_int_type(typename SourceTr::int_type c)
|
---|
29 | {
|
---|
30 | typedef translate_int_type_impl<is_same<SourceTr, TargetTr>::value> impl;
|
---|
31 | return impl::template inner<SourceTr, TargetTr>::translate(c);
|
---|
32 | }
|
---|
33 |
|
---|
34 | //----------------------------------------------------------------------------//
|
---|
35 |
|
---|
36 | template<>
|
---|
37 | struct translate_int_type_impl<true> {
|
---|
38 | template<typename SourceTr, typename TargetTr>
|
---|
39 | struct inner {
|
---|
40 | static typename TargetTr::int_type
|
---|
41 | translate(typename SourceTr::int_type c) { return c; }
|
---|
42 | };
|
---|
43 | };
|
---|
44 |
|
---|
45 | template<>
|
---|
46 | struct translate_int_type_impl<false> {
|
---|
47 | template<typename SourceTr, typename TargetTr>
|
---|
48 | struct inner {
|
---|
49 | static typename TargetTr::int_type
|
---|
50 | translate(typename SourceTr::int_type c)
|
---|
51 | {
|
---|
52 | return SourceTr::eq_int_type(SourceTr::eof()) ?
|
---|
53 | TargetTr::eof() :
|
---|
54 | TargetTr::to_int_type(SourceTr::to_char_type(c));
|
---|
55 | }
|
---|
56 | };
|
---|
57 | };
|
---|
58 |
|
---|
59 | } } } // End namespaces detail, iostreams, boost.
|
---|
60 |
|
---|
61 | #endif // #ifndef BOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED
|
---|