source: NonGTP/Boost/boost/iostreams/detail/translate_int_type.hpp @ 857

Revision 857, 2.0 KB checked in by igarcia, 18 years ago (diff)
Line 
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
16namespace boost { namespace iostreams { namespace detail {
17
18template<bool IsSame>
19struct 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//
26template<typename SourceTr, typename TargetTr>
27typename TargetTr::int_type
28translate_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
36template<>
37struct 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
45template<>
46struct 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
Note: See TracBrowser for help on using the repository browser.