X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fdebugstream.h;h=63744ef4c5014c87bf003dc192211a31ec180db7;hb=da1c04ea9a13dcfe75ad7e727811e9d3004609aa;hp=9340def08cab32f1b50847f891a8156efa94906f;hpb=627f2c70fa6d5c75ef4dfe4e7252adc7c141e6f4;p=lyx.git diff --git a/src/support/debugstream.h b/src/support/debugstream.h index 9340def08c..63744ef4c5 100644 --- a/src/support/debugstream.h +++ b/src/support/debugstream.h @@ -12,8 +12,23 @@ #ifndef DEBUG_STREAM_HPP #define DEBUG_STREAM_HPP -#include +#include +#include + + +//namespace lyx { + +#if BOOST_VERSION < 103300 +# include +#else +# include +#endif + +#ifdef DEBUG +# define TEMPORARY_DEBUG_MACRO DEBUG +# undef DEBUG +#endif struct debug_trait { enum type { @@ -34,6 +49,11 @@ struct debug_trait { } }; +#ifdef TEMPORARY_DEBUG_MACRO +# define DEBUG TEMPORARY_DEBUG_MACRO +# undef TEMPORARY_DEBUG_MACRO +#endif + template (0), dt(debug::NONE), + realbuf_(0), enabled_(true) + {} + /// Constructor, sets the debug level to t. explicit basic_debugstream(std::basic_streambuf * buf) - : std::basic_ostream(buf), dt(debug::NONE) + : std::basic_ostream(buf), dt(debug::NONE), + realbuf_(0), enabled_(true) {} /// Sets the debug level to t. @@ -75,13 +101,37 @@ public: return *this; return nullstream; } + /// Disable the stream completely + void disable() + { + if (enabled_) { + realbuf_ = this->rdbuf(); + rdbuf(nullstream.rdbuf()); + enabled_ = false; + } + } + /// Enable the stream after a possible call of disable() + void enable() + { + if (!enabled_) { + this->rdbuf(realbuf_); + enabled_ = true; + } + } private: /// The current debug level Type dt; /// The no-op stream. boost::basic_onullstream nullstream; + /// The buffer of the real stream + std::streambuf * realbuf_; + /// Is the stream enabled? + bool enabled_; }; typedef basic_debugstream debugstream; + +//} // namespace lyx + #endif