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 enum class target_stream
44 {
45 output,
46 error,
47 log,
48 };
49 winconsole_ostream(target_stream target, bool isBuffered, winconsole_ostream* tieStream);
50 ~winconsole_ostream();
51
52 private:
53 std::unique_ptr<console_output_buffer> d;
54 // Ensure the std streams are initialized and alive during the lifetime of this instance
55 std::ios_base::Init init_;
56 };
57
58 class BOOST_NOWIDE_DECL winconsole_istream : public std::istream
59 {
60 public:
61 explicit winconsole_istream(winconsole_ostream* tieStream);
62 ~winconsole_istream();
63
64 private:
65 std::unique_ptr<console_input_buffer> d;
66 // Ensure the std streams are initialized and alive during the lifetime of this instance
67 std::ios_base::Init init_;
68 };
69 } // namespace detail
70
72
78 extern BOOST_NOWIDE_DECL detail::winconsole_istream cin;
84 extern BOOST_NOWIDE_DECL detail::winconsole_ostream cout;
90 extern BOOST_NOWIDE_DECL detail::winconsole_ostream cerr;
96 extern BOOST_NOWIDE_DECL detail::winconsole_ostream clog;
97
98#endif
99
100} // namespace nowide
101} // namespace boost
102
103#ifdef BOOST_MSVC
104#pragma warning(pop)
105#endif
106
107#ifdef BOOST_WINDOWS
108#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
109#endif
110
111#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.