iostream.hpp 2.9 KB

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