2 // Copyright (c) 2013-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)
8 #ifndef BEAST_UNIT_TEST_DSTREAM_HPP
9 #define BEAST_UNIT_TEST_DSTREAM_HPP
21 # ifndef WIN32_LEAN_AND_MEAN
22 # define WIN32_LEAN_AND_MEAN
25 # undef WIN32_LEAN_AND_MEAN
36 template<class CharT, class Traits, class Allocator>
38 : public std::basic_stringbuf<CharT, Traits, Allocator>
40 using ostream = std::basic_ostream<CharT, Traits>;
46 void write(T const*) = delete;
48 void write(char const* s)
51 OutputDebugStringA(s);
55 void write(wchar_t const* s)
58 OutputDebugStringW(s);
64 dstream_buf(ostream& os)
66 , dbg_(IsDebuggerPresent() != FALSE)
78 write(this->str().c_str());
86 /** std::ostream with Visual Studio IDE redirection.
88 Instances of this stream wrap a specified `std::ostream`
89 (such as `std::cout` or `std::cerr`). If the IDE debugger
90 is attached when the stream is created, output will be
91 additionally copied to the Visual Studio Output window.
95 class Traits = std::char_traits<CharT>,
96 class Allocator = std::allocator<CharT>
99 : public std::basic_ostream<CharT, Traits>
102 CharT, Traits, Allocator> buf_;
105 /** Construct a stream.
107 @param os The output stream to wrap.
110 basic_dstream(std::ostream& os)
111 : std::basic_ostream<CharT, Traits>(&buf_)
114 if(os.flags() & std::ios::unitbuf)
119 using dstream = basic_dstream<char>;
120 using dwstream = basic_dstream<wchar_t>;
124 using dstream = std::ostream&;
125 using dwstream = std::wostream&;