Boost.Nowide
iostream.hpp
1 //
2 // Copyright (c) 2012 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt 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 <boost/scoped_ptr.hpp>
14 #include <istream>
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  winconsole_ostream(const winconsole_ostream&);
44  void operator=(const winconsole_ostream&);
45 
46  public:
47  winconsole_ostream(int fd, winconsole_ostream* tieStream);
48  ~winconsole_ostream();
49 
50  private:
51  boost::scoped_ptr<console_output_buffer> d;
52  };
53 
54  class BOOST_NOWIDE_DECL winconsole_istream : public std::istream
55  {
56  winconsole_istream(const winconsole_istream&);
57  void operator=(const winconsole_istream&);
58 
59  public:
60  explicit winconsole_istream(winconsole_ostream* tieStream);
61  ~winconsole_istream();
62 
63  private:
64  boost::scoped_ptr<console_input_buffer> d;
65  };
66  } // namespace detail
67 
69 
75  extern BOOST_NOWIDE_DECL detail::winconsole_istream cin;
81  extern BOOST_NOWIDE_DECL detail::winconsole_ostream cout;
87  extern BOOST_NOWIDE_DECL detail::winconsole_ostream cerr;
93  extern BOOST_NOWIDE_DECL detail::winconsole_ostream clog;
94 
95 #endif
96 
97 } // namespace nowide
98 } // namespace boost
99 
100 #ifdef BOOST_MSVC
101 #pragma warning(pop)
102 #endif
103 
104 #ifdef BOOST_WINDOWS
105 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
106 #endif
107 
108 #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.