1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2003-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED
15 #include <boost/type_traits/is_same.hpp>
17 namespace boost { namespace iostreams { namespace detail {
20 struct translate_int_type_impl;
23 // Template name: translate_char.
24 // Description: Translates a character or an end-of-file indicator from the
25 // int_type of one character traits type to the int_type of another.
27 template<typename SourceTr, typename TargetTr>
28 typename TargetTr::int_type
29 translate_int_type(typename SourceTr::int_type c)
31 typedef translate_int_type_impl<is_same<SourceTr, TargetTr>::value> impl;
32 return impl::template inner<SourceTr, TargetTr>::translate(c);
35 //----------------------------------------------------------------------------//
38 struct translate_int_type_impl<true> {
39 template<typename SourceTr, typename TargetTr>
41 static typename TargetTr::int_type
42 translate(typename SourceTr::int_type c) { return c; }
47 struct translate_int_type_impl<false> {
48 template<typename SourceTr, typename TargetTr>
50 static typename TargetTr::int_type
51 translate(typename SourceTr::int_type c)
53 return SourceTr::eq_int_type(SourceTr::eof()) ?
55 TargetTr::to_int_type(SourceTr::to_char_type(c));
60 } } } // End namespaces detail, iostreams, boost.
62 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED