]> git.lyx.org Git - lyx.git/blob - src/client/debug.h
Embedding: saving inzip name to .lyx file so that embedded files can always be found...
[lyx.git] / src / client / debug.h
1 // -*- C++ -*-
2 /**
3  * \file debug.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LYXDEBUG_H
14 #define LYXDEBUG_H
15
16 #include "support/docstring.h"
17
18
19 namespace lyx {
20
21 /** Ideally this should have been a namespace, but since we try to be
22  *  compilable on older C++ compilators too, we use a struct instead.
23  *  This is all the different debug levels that we have.
24  */
25 class Debug {
26 public:
27         ///
28         enum Type {
29                 ///
30                 NONE = 0,
31                 ///
32                 INFO       = (1 << 0),
33                 ///
34                 DEBUG      = (1 << 31),
35                 ///
36                 ANY = 0xffffffff
37         };
38
39         /** A function to convert symbolic string names on debug levels
40             to their numerical value.
41         */
42         static Type value(std::string const & val);
43
44         /** Display the tags and descriptions of the current debug level
45             of ds
46         */
47         static void showLevel(std::ostream & o, Type level);
48
49         /** show all the possible tags that can be used for debugging */
50         static void showTags(std::ostream & o);
51
52 };
53
54
55 inline void operator|=(Debug::Type & d1, Debug::Type d2)
56 {
57         d1 = static_cast<Debug::Type>(d1 | d2);
58 }
59
60
61 class LyXErr
62 {
63 public:
64         /// Disable the stream completely
65         void disable();
66         /// Enable the stream after a possible call of disable()
67         void enable();
68         /// Returns true if t is part of the current debug level.
69         bool debugging(Debug::Type t = Debug::ANY) const;
70         /// Ends output
71         void endl();
72         /// Sets stream
73         void setStream(std::ostream & os) { stream_ = &os; }
74         /// Sets stream
75         std::ostream & stream() { return *stream_; }
76         /// Sets the debug level to t.
77         void level(Debug::Type t) { dt = t; }
78         /// Returns the current debug level.
79         Debug::Type level() const { return dt; }
80         /// Returns stream
81         operator std::ostream &() { return *stream_; }
82 private:
83         /// The current debug level
84         Debug::Type dt;
85         /// Is the stream enabled?
86         bool enabled_;
87         /// The real stream
88         std::ostream * stream_;
89 };
90
91 namespace support { class FileName; }
92
93 LyXErr & operator<<(LyXErr &, void const *);
94 LyXErr & operator<<(LyXErr &, char const *);
95 LyXErr & operator<<(LyXErr &, char);
96 LyXErr & operator<<(LyXErr &, int);
97 LyXErr & operator<<(LyXErr &, unsigned int);
98 LyXErr & operator<<(LyXErr &, long);
99 LyXErr & operator<<(LyXErr &, unsigned long);
100 LyXErr & operator<<(LyXErr &, double);
101 LyXErr & operator<<(LyXErr &, std::string const &);
102 LyXErr & operator<<(LyXErr &, docstring const &);
103 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
104 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
105 LyXErr & operator<<(LyXErr & l, support::FileName const & t);
106
107 extern LyXErr lyxerr;
108
109 } // namespace lyx
110
111 #define LYXERR(type, msg) \
112         do { if (!lyx::lyxerr.debugging(type)) {} \
113        else lyx::lyxerr << msg  << std::endl; } while (0)
114
115
116 #endif