Boost.Nowide
iostream.hpp
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 // (See accompanying file LICENSE 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 
11 #include <boost/nowide/config.hpp>
12 #ifdef BOOST_WINDOWS
13 #include <istream>
14 #include <memory>
15 #include <ostream>
16 
17 #include <boost/config/abi_prefix.hpp> // must be the last #include
18 #else
19 #include <iostream>
20 #endif
21 
22 #ifdef BOOST_MSVC
23 #pragma warning(push)
24 #pragma warning(disable : 4251)
25 #endif
26 
27 namespace boost {
28 namespace nowide {
29 #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
30  using std::cout;
31  using std::cerr;
32  using std::cin;
33  using std::clog;
34 #else
35 
37  namespace detail {
38  class console_output_buffer;
39  class console_input_buffer;
40 
41  class BOOST_NOWIDE_DECL winconsole_ostream : public std::ostream
42  {
43  public:
44  winconsole_ostream(int fd, winconsole_ostream* tieStream);
45  ~winconsole_ostream();
46 
47  private:
48  std::unique_ptr<console_output_buffer> d;
49  // Ensure the std streams are initialized and alive during the lifetime of this instance
50  std::ios_base::Init init_;
51  };
52 
53  class BOOST_NOWIDE_DECL winconsole_istream : public std::istream
54  {
55  public:
56  explicit winconsole_istream(winconsole_ostream* tieStream);
57  ~winconsole_istream();
58 
59  private:
60  std::unique_ptr<console_input_buffer> d;
61  // Ensure the std streams are initialized and alive during the lifetime of this instance
62  std::ios_base::Init init_;
63  };
64  } // namespace detail
65 
67 
73  extern BOOST_NOWIDE_DECL detail::winconsole_istream cin;
79  extern BOOST_NOWIDE_DECL detail::winconsole_ostream cout;
85  extern BOOST_NOWIDE_DECL detail::winconsole_ostream cerr;
91  extern BOOST_NOWIDE_DECL detail::winconsole_ostream clog;
92 
93 #endif
94 
95 } // namespace nowide
96 } // namespace boost
97 
98 #ifdef BOOST_MSVC
99 #pragma warning(pop)
100 #endif
101 
102 #ifdef BOOST_WINDOWS
103 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
104 #endif
105 
106 #endif
detail::winconsole_istream cin
Same as std::cin, but uses UTF-8.
detail::winconsole_ostream cout
Same as std::cout, but uses UTF-8.
detail::winconsole_ostream cerr
Same as std::cerr, but uses UTF-8.
detail::winconsole_ostream clog
Same as std::clog, but uses UTF-8.