2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_UNIT_TEST_DSTREAM_HPP
11 #define BOOST_BEAST_UNIT_TEST_DSTREAM_HPP
13 #include <boost/config.hpp>
21 #include <boost/winapi/basic_types.hpp>
22 #include <boost/winapi/debugapi.hpp>
33 template<class CharT, class Traits, class Allocator>
35 : public std::basic_stringbuf<CharT, Traits, Allocator>
37 using ostream = std::basic_ostream<CharT, Traits>;
43 void write(T const*) = delete;
45 void write(char const* s)
48 boost::winapi::OutputDebugStringA(s);
52 void write(wchar_t const* s)
55 boost::winapi::OutputDebugStringW(s);
61 dstream_buf(ostream& os)
63 , dbg_(boost::winapi::IsDebuggerPresent() != 0)
75 write(this->str().c_str());
83 /** std::ostream with Visual Studio IDE redirection.
85 Instances of this stream wrap a specified `std::ostream`
86 (such as `std::cout` or `std::cerr`). If the IDE debugger
87 is attached when the stream is created, output will be
88 additionally copied to the Visual Studio Output window.
92 class Traits = std::char_traits<CharT>,
93 class Allocator = std::allocator<CharT>
96 : public std::basic_ostream<CharT, Traits>
99 CharT, Traits, Allocator> buf_;
102 /** Construct a stream.
104 @param os The output stream to wrap.
107 basic_dstream(std::ostream& os)
108 : std::basic_ostream<CharT, Traits>(&buf_)
111 if(os.flags() & std::ios::unitbuf)
116 using dstream = basic_dstream<char>;
117 using dwstream = basic_dstream<wchar_t>;
121 using dstream = std::ostream&;
122 using dwstream = std::wostream&;