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