char_traits.hpp 2.4 KB

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