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