iostream.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // Copyright (c) 2012 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOST_NOWIDE_IOSTREAM_HPP_INCLUDED
  9. #define BOOST_NOWIDE_IOSTREAM_HPP_INCLUDED
  10. #include <boost/nowide/config.hpp>
  11. #ifdef BOOST_WINDOWS
  12. #include <boost/scoped_ptr.hpp>
  13. #include <istream>
  14. #include <ostream>
  15. #include <boost/config/abi_prefix.hpp> // must be the last #include
  16. #else
  17. #include <iostream>
  18. #endif
  19. #ifdef BOOST_MSVC
  20. #pragma warning(push)
  21. #pragma warning(disable : 4251)
  22. #endif
  23. namespace boost {
  24. namespace nowide {
  25. #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
  26. using std::cout;
  27. using std::cerr;
  28. using std::cin;
  29. using std::clog;
  30. #else
  31. /// \cond INTERNAL
  32. namespace detail {
  33. class console_output_buffer;
  34. class console_input_buffer;
  35. class BOOST_NOWIDE_DECL winconsole_ostream : public std::ostream
  36. {
  37. winconsole_ostream(const winconsole_ostream&);
  38. void operator=(const winconsole_ostream&);
  39. public:
  40. winconsole_ostream(int fd, winconsole_ostream* tieStream);
  41. ~winconsole_ostream();
  42. private:
  43. boost::scoped_ptr<console_output_buffer> d;
  44. };
  45. class BOOST_NOWIDE_DECL winconsole_istream : public std::istream
  46. {
  47. winconsole_istream(const winconsole_istream&);
  48. void operator=(const winconsole_istream&);
  49. public:
  50. explicit winconsole_istream(winconsole_ostream* tieStream);
  51. ~winconsole_istream();
  52. private:
  53. boost::scoped_ptr<console_input_buffer> d;
  54. };
  55. } // namespace detail
  56. /// \endcond
  57. ///
  58. /// \brief Same as std::cin, but uses UTF-8
  59. ///
  60. /// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
  61. ///
  62. extern BOOST_NOWIDE_DECL detail::winconsole_istream cin;
  63. ///
  64. /// \brief Same as std::cout, but uses UTF-8
  65. ///
  66. /// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
  67. ///
  68. extern BOOST_NOWIDE_DECL detail::winconsole_ostream cout;
  69. ///
  70. /// \brief Same as std::cerr, but uses UTF-8
  71. ///
  72. /// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
  73. ///
  74. extern BOOST_NOWIDE_DECL detail::winconsole_ostream cerr;
  75. ///
  76. /// \brief Same as std::clog, but uses UTF-8
  77. ///
  78. /// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
  79. ///
  80. extern BOOST_NOWIDE_DECL detail::winconsole_ostream clog;
  81. #endif
  82. } // namespace nowide
  83. } // namespace boost
  84. #ifdef BOOST_MSVC
  85. #pragma warning(pop)
  86. #endif
  87. #ifdef BOOST_WINDOWS
  88. #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
  89. #endif
  90. #endif