]> git.lyx.org Git - lyx.git/blobdiff - src/client/debug.h
* new function to set border around selection
[lyx.git] / src / client / debug.h
index f0c604a78041bae1c7e6f2781b1ed19afd917bb5..8f0237fffc0f5b0ef9882e728f5a45ba2ce4b515 100644 (file)
@@ -13,7 +13,6 @@
 #ifndef LYXDEBUG_H
 #define LYXDEBUG_H
 
-#include "support/debugstream.h"
 #include "support/docstring.h"
 
 
@@ -23,10 +22,10 @@ namespace lyx {
  *  compilable on older C++ compilators too, we use a struct instead.
  *  This is all the different debug levels that we have.
  */
-class lyx_debug_trait {
+class Debug {
 public:
        ///
-       enum type {
+       enum Type {
                ///
                NONE = 0,
                ///
@@ -37,19 +36,15 @@ public:
                ANY = 0xffffffff
        };
 
-       static bool match(type a, type b) {
-               return (a & b);
-       }
-
        /** A function to convert symbolic string names on debug levels
            to their numerical value.
        */
-       static type value(std::string const & val);
+       static Type value(std::string const & val);
 
        /** Display the tags and descriptions of the current debug level
            of ds
        */
-       static void showLevel(std::ostream & o, type level);
+       static void showLevel(std::ostream & o, Type level);
 
        /** show all the possible tags that can be used for debugging */
        static void showTags(std::ostream & o);
@@ -57,22 +52,65 @@ public:
 };
 
 
-
-inline
-void operator|=(lyx_debug_trait::type & d1, lyx_debug_trait::type d2)
+inline void operator|=(Debug::Type & d1, Debug::Type d2)
 {
-       d1 = static_cast<lyx_debug_trait::type>(d1 | d2);
+       d1 = static_cast<Debug::Type>(d1 | d2);
 }
 
 
-typedef basic_debugstream<lyx_debug_trait> LyXErr;
-typedef LyXErr::debug Debug;
+class LyXErr
+{
+public:
+       /// Disable the stream completely
+       void disable();
+       /// Enable the stream after a possible call of disable()
+       void enable();
+       /// Returns true if t is part of the current debug level.
+       bool debugging(Debug::Type t = Debug::ANY) const;
+       /// Ends output
+       void endl();
+       /// Sets stream
+       void setStream(std::ostream & os) { stream_ = &os; }
+       /// Sets stream
+       std::ostream & stream() { return *stream_; }
+       /// Sets the debug level to t.
+       void level(Debug::Type t) { dt = t; }
+       /// Returns the current debug level.
+       Debug::Type level() const { return dt; }
+       /// Returns stream
+       operator std::ostream &() { return *stream_; }
+private:
+       /// The current debug level
+       Debug::Type dt;
+       /// Is the stream enabled?
+       bool enabled_;
+       /// The real stream
+       std::ostream * stream_;
+};
+
+namespace support { class FileName; }
+
+LyXErr & operator<<(LyXErr &, void const *);
+LyXErr & operator<<(LyXErr &, char const *);
+LyXErr & operator<<(LyXErr &, char);
+LyXErr & operator<<(LyXErr &, int);
+LyXErr & operator<<(LyXErr &, unsigned int);
+LyXErr & operator<<(LyXErr &, long);
+LyXErr & operator<<(LyXErr &, unsigned long);
+LyXErr & operator<<(LyXErr &, double);
+LyXErr & operator<<(LyXErr &, std::string const &);
+LyXErr & operator<<(LyXErr &, docstring const &);
+LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
+LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
+LyXErr & operator<<(LyXErr & l, support::FileName const & t);
 
 extern LyXErr lyxerr;
 
 } // namespace lyx
 
-#define LYXERR(type) if (!lyx::lyxerr.debugging(type)) ; else lyx::lyxerr
+#define LYXERR(type, msg) \
+       do { if (!lyx::lyxerr.debugging(type)) {} \
+       else lyx::lyxerr << msg  << std::endl; } while (0)
 
 
 #endif