4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
12 #ifndef DEBUG_STREAM_HPP
13 #define DEBUG_STREAM_HPP
17 #include <boost/version.hpp>
19 #if BOOST_VERSION < 103300
20 # include <boost/test/detail/nullstream.hpp>
22 # include <boost/test/utils/nullstream.hpp>
26 # define TEMPORARY_DEBUG_MACRO DEBUG
44 static bool match(type a, type b) {
45 return (b <= a || (b == ANY && a > NONE));
49 #ifdef TEMPORARY_DEBUG_MACRO
50 # define DEBUG TEMPORARY_DEBUG_MACRO
51 # undef TEMPORARY_DEBUG_MACRO
55 template <class dtrait,
57 class traits = std::char_traits<charT> >
58 class basic_debugstream : public std::basic_ostream<charT, traits> {
61 typedef typename debug::type Type;
64 : std::basic_ostream<charT, traits>(0), dt(debug::NONE)
67 /// Constructor, sets the debug level to t.
68 explicit basic_debugstream(std::basic_streambuf<charT, traits> * buf)
69 : std::basic_ostream<charT, traits>(buf), dt(debug::NONE)
72 /// Sets the debug level to t.
77 /// Returns the current debug level.
82 /// Returns true if t is part of the current debug level.
83 bool debugging(Type t = debug::ANY) const
85 if (debug::match(dt, t)) return true;
89 /** Returns the no-op stream if t is not part of the
90 current debug level otherwise the real debug stream
92 Use: dbgstream[Debug::INFO] << "Info!\n";
94 std::basic_ostream<charT, traits> & operator[](Type t) {
95 if (debug::match(dt, t))
100 /// The current debug level
102 /// The no-op stream.
103 boost::basic_onullstream<charT, traits> nullstream;
106 typedef basic_debugstream<debug_trait> debugstream;