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_CHAR_TRAITS_HPP_INCLUDED |
---|
8 | #define BOOST_IOSTREAMS_CHAR_TRAITS_HPP_INCLUDED |
---|
9 | |
---|
10 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) |
---|
11 | # pragma once |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <boost/config.hpp> |
---|
15 | #include <cstddef> |
---|
16 | #include <cstdio> // EOF. |
---|
17 | #include <string> // std::char_traits. |
---|
18 | #include <boost/iostreams/detail/char_traits.hpp> |
---|
19 | #include <boost/iostreams/detail/config/wide_streams.hpp> |
---|
20 | #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS |
---|
21 | # include <cwchar> |
---|
22 | #endif |
---|
23 | |
---|
24 | #ifdef BOOST_NO_STDC_NAMESPACE |
---|
25 | namespace std { using ::wint_t; } |
---|
26 | #endif |
---|
27 | |
---|
28 | namespace boost { namespace iostreams { |
---|
29 | |
---|
30 | // Dinkumware that comes with QNX Momentics 6.3.0, 4.0.2, incorrectly defines |
---|
31 | // the EOF and WEOF macros to not std:: qualify the wint_t type (and so does |
---|
32 | // Sun C++ 5.8 + STLport 4). Fix by placing the def in this scope. |
---|
33 | // NOTE: Use BOOST_WORKAROUND? |
---|
34 | #if (defined(__QNX__) && defined(BOOST_DINKUMWARE_STDLIB)) \ |
---|
35 | || defined(__SUNPRO_CC) |
---|
36 | using ::std::wint_t; |
---|
37 | #endif |
---|
38 | |
---|
39 | const int WOULD_BLOCK = (int) (EOF - 1); |
---|
40 | |
---|
41 | #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS |
---|
42 | const std::wint_t WWOULD_BLOCK = (std::wint_t) (WEOF - 1); |
---|
43 | #endif |
---|
44 | |
---|
45 | template<typename Ch> |
---|
46 | struct char_traits; |
---|
47 | |
---|
48 | template<> |
---|
49 | struct char_traits<char> : BOOST_IOSTREAMS_CHAR_TRAITS(char) { |
---|
50 | static char newline() { return '\n'; } |
---|
51 | static int good() { return '\n'; } |
---|
52 | static int would_block() { return WOULD_BLOCK; } |
---|
53 | static bool is_good(int c) { return c != EOF && c != WOULD_BLOCK; } |
---|
54 | static bool is_eof(int c) { return c == EOF; } |
---|
55 | static bool would_block(int c) { return c == WOULD_BLOCK; } |
---|
56 | }; |
---|
57 | |
---|
58 | #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS |
---|
59 | template<> |
---|
60 | struct char_traits<wchar_t> : std::char_traits<wchar_t> { |
---|
61 | static wchar_t newline() { return L'\n'; } |
---|
62 | static std::wint_t good() { return L'\n'; } |
---|
63 | static std::wint_t would_block() { return WWOULD_BLOCK; } |
---|
64 | static bool is_good(std::wint_t c) { return c != WEOF && c != WWOULD_BLOCK; } |
---|
65 | static bool is_eof(std::wint_t c) { return c == WEOF; } |
---|
66 | static bool would_block(std::wint_t c) { return c == WWOULD_BLOCK; } |
---|
67 | }; |
---|
68 | #endif |
---|
69 | |
---|
70 | } } // End namespaces iostreams, boost. |
---|
71 | |
---|
72 | #endif // #ifndef BOOST_IOSTREAMS_CHAR_TRAITS_HPP_INCLUDED |
---|