]> git.lyx.org Git - lyx.git/blobdiff - src/support/debug.h
add generic helper class for calling functions in gui thread
[lyx.git] / src / support / debug.h
index c68a379e913c818fe4bd37c0144438f029440bb8..26bfd25ab80605252320f8fc70955dd2cc8769ed 100644 (file)
@@ -9,8 +9,9 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Jean-Marc Lasgouttes
+ * \author Pavel Sanda
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -20,7 +21,6 @@
 
 #include "support/strfwd.h"
 
-
 namespace std {
 
 class ios_base;
@@ -66,7 +66,7 @@ namespace Debug {
                ///
                LYXSERVER  = (1 << 12),  // 4096
                ///
-               ROFF       = (1 << 13),  // 8192
+               UNDO       = (1 << 13),  // 8192
                ///
                ACTION     = (1 << 14),   // 16384
                ///
@@ -90,16 +90,44 @@ namespace Debug {
                ///
                PAINTING   = (1 << 24),
                ///
+               SCROLLING  = (1 << 25),
+               ///
+               MACROS     = (1 << 26),
+               ///     rtl-related
+               RTL        = (1 << 27),
+               ///     locale related
+               LOCALE     = (1 << 28),
+               ///     selection
+               SELECTION  = (1 << 29),
+               /// Find and Replace
+               FIND       = (1 << 30),
+               ///
                DEBUG      = (1 << 31),
                ///
                ANY = 0xffffffff
        };
 
+
+       // Return number of levels
+       int levelCount();
+
        /** A function to convert symbolic string names on debug levels
            to their numerical value.
        */
        Type value(std::string const & val);
 
+       /** A function to convert index of level to their numerical value.
+       */
+       Type value(int val);
+
+       /// Return description of level
+       std::string const description(Type val);
+
+       /// Return name of level
+       std::string const name(Type val);
+
+
        /** Display the tags and descriptions of the current debug level
            of ds
        */
@@ -120,7 +148,7 @@ inline void operator|=(Debug::Type & d1, Debug::Type d2)
 class LyXErr
 {
 public:
-       LyXErr(): enabled_(true) {}
+       LyXErr(): enabled_(true), second_used_(false) {}
        /// Disable the stream completely
        void disable();
        /// Enable the stream after a possible call of disable()
@@ -136,11 +164,18 @@ public:
        /// Sets stream
        std::ostream & stream() { return *stream_; }
        /// Sets the debug level to t.
-       void level(Debug::Type t) { dt = t; }
+       void setLevel(Debug::Type t) { dt = t; }
        /// Returns the current debug level.
        Debug::Type level() const { return dt; }
        /// Returns stream
        operator std::ostream &() { return *stream_; }
+       /// Returns second_used_
+       bool second_used() { return second_used_; }
+       // Returns second stream
+       std::ostream & second() { return *second_; };
+       /// Sets the second stream
+       void setSecond(std::ostream * os) { second_used_ = (second_ = os); }
+
 private:
        /// The current debug level
        Debug::Type dt;
@@ -148,6 +183,10 @@ private:
        bool enabled_;
        /// The real stream
        std::ostream * stream_;
+       /// Next stream for output duplication
+       std::ostream * second_;
+       /// Is the second stream enabled?
+       bool second_used_;
 };
 
 namespace support { class FileName; }
@@ -183,6 +222,10 @@ extern LyXErr lyxerr;
                else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
        } while (0)
 
-#define LYXERR0(msg) LYXERR(lyx::Debug::ANY, msg)
+#define LYXERR0(msg) \
+       do { \
+               lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
+       } while (0)
+
 
 #endif