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// https://www.boost.org/LICENSE_1_0.txt
6
7#ifndef BOOST_NOWIDE_IOSTREAM_HPP_INCLUDED
8#define BOOST_NOWIDE_IOSTREAM_HPP_INCLUDED
9
11#ifdef BOOST_WINDOWS
12#include <istream>
13#include <memory>
14#include <ostream>
15
16#include <boost/config/abi_prefix.hpp> // must be the last #include
17#else
18#include <iostream>
19#endif
20
21#ifdef BOOST_MSVC
22#pragma warning(push)
23#pragma warning(disable : 4251)
24#endif
25
26namespace boost {
27namespace nowide {
28#if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
29 using std::cout;
30 using std::cerr;
31 using std::cin;
32 using std::clog;
33#else
34
36 namespace detail {
37 class console_output_buffer;
38 class console_input_buffer;
39
40 class BOOST_NOWIDE_DECL winconsole_ostream : public std::ostream
41 {
42 public:
43 winconsole_ostream(bool isBuffered, winconsole_ostream* tieStream);
44 ~winconsole_ostream();
45
46 private:
47 std::unique_ptr<console_output_buffer> d;
48 // Ensure the std streams are initialized and alive during the lifetime of this instance
49 std::ios_base::Init init_;
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 // Ensure the std streams are initialized and alive during the lifetime of this instance
61 std::ios_base::Init init_;
62 };
63 } // namespace detail
64
66
72 extern BOOST_NOWIDE_DECL detail::winconsole_istream cin;
78 extern BOOST_NOWIDE_DECL detail::winconsole_ostream cout;
84 extern BOOST_NOWIDE_DECL detail::winconsole_ostream cerr;
90 extern BOOST_NOWIDE_DECL detail::winconsole_ostream clog;
91
92#endif
93
94} // namespace nowide
95} // namespace boost
96
97#ifdef BOOST_MSVC
98#pragma warning(pop)
99#endif
100
101#ifdef BOOST_WINDOWS
102#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
103#endif
104
105#endif
detail::winconsole_ostream clog
Same as std::clog, but uses UTF-8.
detail::winconsole_istream cin
Same as std::cin, but uses UTF-8.
detail::winconsole_ostream cerr
Same as std::cerr, but uses UTF-8.
detail::winconsole_ostream cout
Same as std::cout, but uses UTF-8.