]> git.lyx.org Git - lyx.git/blobdiff - src/support/debugstream.h
fix linking error in the frontend
[lyx.git] / src / support / debugstream.h
index 9619720f6b49f1d46a06fe5798735f7f62adfb70..63744ef4c5014c87bf003dc192211a31ec180db7 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file debugStream.h
+ * \file debugstream.h
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 #ifndef DEBUG_STREAM_HPP
 #define DEBUG_STREAM_HPP
 
-#include <boost/test/detail/nullstream.hpp>
+#include <iostream>
 
+#include <boost/version.hpp>
+
+
+//namespace lyx {
+
+#if BOOST_VERSION < 103300
+#  include <boost/test/detail/nullstream.hpp>
+#else
+#  include <boost/test/utils/nullstream.hpp>
+#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 <class dtrait,
          class charT = char,
@@ -43,9 +63,15 @@ public:
        typedef dtrait debug;
        typedef typename debug::type Type;
 
+       basic_debugstream()
+               : std::basic_ostream<charT, traits>(0), dt(debug::NONE),
+                 realbuf_(0), enabled_(true)
+       {}
+
        /// Constructor, sets the debug level to t.
        explicit basic_debugstream(std::basic_streambuf<charT, traits> * buf)
-               : std::basic_ostream<charT, traits>(buf), dt(debug::NONE)
+               : std::basic_ostream<charT, traits>(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<charT, traits> nullstream;
+       /// The buffer of the real stream
+       std::streambuf * realbuf_;
+       /// Is the stream enabled?
+       bool enabled_;
 };
 
 typedef basic_debugstream<debug_trait> debugstream;
 
+
+//} // namespace lyx
+
 #endif