iostream.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. enum class target_stream
  37. {
  38. output,
  39. error,
  40. log,
  41. };
  42. winconsole_ostream(target_stream target, bool isBuffered, winconsole_ostream* tieStream);
  43. ~winconsole_ostream();
  44. private:
  45. std::unique_ptr<console_output_buffer> d;
  46. // Ensure the std streams are initialized and alive during the lifetime of this instance
  47. std::ios_base::Init init_;
  48. };
  49. class BOOST_NOWIDE_DECL winconsole_istream : public std::istream
  50. {
  51. public:
  52. explicit winconsole_istream(winconsole_ostream* tieStream);
  53. ~winconsole_istream();
  54. private:
  55. std::unique_ptr<console_input_buffer> d;
  56. // Ensure the std streams are initialized and alive during the lifetime of this instance
  57. std::ios_base::Init init_;
  58. };
  59. } // namespace detail
  60. /// \endcond
  61. ///
  62. /// \brief Same as std::cin, 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_istream cin;
  67. ///
  68. /// \brief Same as std::cout, 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 cout;
  73. ///
  74. /// \brief Same as std::cerr, 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 cerr;
  79. ///
  80. /// \brief Same as std::clog, but uses UTF-8
  81. ///
  82. /// Note, the stream is not synchronized with stdio and not affected by std::ios::sync_with_stdio
  83. ///
  84. extern BOOST_NOWIDE_DECL detail::winconsole_ostream clog;
  85. #endif
  86. } // namespace nowide
  87. } // namespace boost
  88. #ifdef BOOST_MSVC
  89. #pragma warning(pop)
  90. #endif
  91. #ifdef BOOST_WINDOWS
  92. #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
  93. #endif
  94. #endif