Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 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.) |
| 5 | |
| 6 | // See http://www.boost.org/libs/iostreams for documentation. |
| 7 | |
| 8 | #ifndef NDNBOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED |
| 9 | #define NDNBOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED |
| 10 | |
| 11 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
| 12 | # pragma once |
| 13 | #endif |
| 14 | |
| 15 | #include <ndnboost/type_traits/is_same.hpp> |
| 16 | |
| 17 | namespace ndnboost { namespace iostreams { namespace detail { |
| 18 | |
| 19 | template<bool IsSame> |
| 20 | struct translate_int_type_impl; |
| 21 | |
| 22 | // |
| 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. |
| 26 | // |
| 27 | template<typename SourceTr, typename TargetTr> |
| 28 | typename TargetTr::int_type |
| 29 | translate_int_type(typename SourceTr::int_type c) |
| 30 | { |
| 31 | typedef translate_int_type_impl<is_same<SourceTr, TargetTr>::value> impl; |
| 32 | return impl::template inner<SourceTr, TargetTr>::translate(c); |
| 33 | } |
| 34 | |
| 35 | //----------------------------------------------------------------------------// |
| 36 | |
| 37 | template<> |
| 38 | struct translate_int_type_impl<true> { |
| 39 | template<typename SourceTr, typename TargetTr> |
| 40 | struct inner { |
| 41 | static typename TargetTr::int_type |
| 42 | translate(typename SourceTr::int_type c) { return c; } |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | template<> |
| 47 | struct translate_int_type_impl<false> { |
| 48 | template<typename SourceTr, typename TargetTr> |
| 49 | struct inner { |
| 50 | static typename TargetTr::int_type |
| 51 | translate(typename SourceTr::int_type c) |
| 52 | { |
| 53 | return SourceTr::eq_int_type(SourceTr::eof()) ? |
| 54 | TargetTr::eof() : |
| 55 | TargetTr::to_int_type(SourceTr::to_char_type(c)); |
| 56 | } |
| 57 | }; |
| 58 | }; |
| 59 | |
| 60 | } } } // End namespaces detail, iostreams, boost. |
| 61 | |
| 62 | #endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_TRANSLATE_INT_TYPE_HPP_INCLUDED |