5 * This file is part of LyX, the document processor.
6 * Licence details can be found in the file COPYING.
8 * \author Lars Gullik Bjønnes
9 * \author Jean-Marc Lasgouttes
12 * Full author contact details are available in file CREDITS.
18 #include "support/strfwd.h"
20 // Forward definitions do not work with libc++
21 // but ios_base has already been defined in strfwd
22 // if compiling with it
23 #ifndef USE_LLVM_LIBCPP
28 template<typename CharT, typename Traits> class basic_streambuf;
29 typedef basic_streambuf<char, char_traits<char> > streambuf;
35 // Make sure at compile time that sizeof(unsigned long long) >= 8
36 typedef char p__LINE__[ (sizeof(unsigned long long) > 7) ? 1 : -1];
40 /// This is all the different debug levels that we have.
43 typedef unsigned long long base_type;
44 enum Type : base_type {
48 INFO = (1u << 0), // 1
50 INIT = (1u << 1), // 2
56 PARSER = (1u << 4), // 16
58 LYXRC = (1u << 5), // 32
60 KBMAP = (1u << 6), // 64
62 OUTFILE = (1u << 7), // 128
64 MATHED = (1u << 8), // 256 // Alejandro, please use this.
66 FONT = (1u << 9), // 512
68 TCLASS = (1u << 10), // 1024
70 LYXVC = (1u << 11), // 2048
72 LYXSERVER = (1u << 12), // 4096
74 UNDO = (1u << 13), // 8192
76 ACTION = (1u << 14), // 16384
86 WORKAREA = (1u << 19),
88 CLIPBOARD = (1u << 20),
90 GRAPHICS = (1u << 21),
94 EXTERNAL = (1u << 23),
96 PAINTING = (1u << 24),
98 SCROLLING = (1u << 25),
106 SELECTION = (1u << 29),
110 FINDVERBOSE= (1u << 31),
112 DEBUG = (1ULL << 32),
117 /// Return number of levels
120 /// A function to convert debug level string names numerical values
121 Type value(std::string const & val);
123 /// Check the validity of debug level names
124 /// \return the first bad level name
125 std::string badValue(std::string const & val);
127 /// A function to convert index of level to their numerical value
130 /// Return description of level
131 std::string const description(Type val);
133 /// Return name of level from value. In case of aliases,
134 /// this returns the first entry found
135 std::string const name(Type val);
137 /// Return name of level from index, in case of aliases
138 /// this is unambiguous
139 std::string const realName(int i);
141 /// Display the tags and descriptions of the current debug level
142 void showLevel(std::ostream & os, Type level);
144 /// Show all the possible tags that can be used for debugging
145 void showTags(std::ostream & os);
151 inline void operator|=(Debug::Type & d1, Debug::Type d2)
153 d1 = static_cast<Debug::Type>(d1 | d2);
160 LyXErr(): dt_(Debug::NONE), stream_(0), enabled_(true),
161 second_stream_(0), second_enabled_(false) {}
163 /// Disable the stream completely
165 /// Enable the stream after a possible call of disable()
172 std::ostream & stream() { return *stream_; }
174 operator std::ostream &() { return *stream_; }
176 void setStream(std::ostream & os) { stream_ = &os; }
177 /// Is the stream enabled ?
178 bool enabled() const { return enabled_; }
180 /// Returns second stream
181 std::ostream & secondStream() { return *second_stream_; }
182 /// Sets second stream
183 void setSecondStream(std::ostream * os)
184 { second_enabled_ = (second_stream_ = os); }
185 /// Is the second stream is enabled?
186 bool secondEnabled() const { return second_enabled_; }
188 /// Sets the debug level
189 void setLevel(Debug::Type t) { dt_ = t; }
190 /// Returns the current debug level
191 Debug::Type level() const { return dt_; }
192 /// Returns true if t is part of the current debug level
193 bool debugging(Debug::base_type t = Debug::ANY) const;
196 static char const * stripName(char const *);
199 /// The current debug level
202 std::ostream * stream_;
203 /// Is the stream enabled?
205 /// Next stream for output duplication
206 std::ostream * second_stream_;
207 /// Is the second stream enabled?
208 bool second_enabled_;
211 namespace support { class FileName; }
213 LyXErr & operator<<(LyXErr &, void const *);
214 LyXErr & operator<<(LyXErr &, char const *);
215 LyXErr & operator<<(LyXErr &, char);
216 LyXErr & operator<<(LyXErr &, int);
217 LyXErr & operator<<(LyXErr &, unsigned int);
218 LyXErr & operator<<(LyXErr &, long);
219 LyXErr & operator<<(LyXErr &, unsigned long);
220 #ifdef HAVE_LONG_LONG_INT
221 LyXErr & operator<<(LyXErr &, long long);
222 LyXErr & operator<<(LyXErr &, unsigned long long);
224 LyXErr & operator<<(LyXErr &, double);
225 LyXErr & operator<<(LyXErr &, std::string const &);
226 LyXErr & operator<<(LyXErr &, docstring const &);
227 LyXErr & operator<<(LyXErr &, support::FileName const &);
228 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
229 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
231 extern LyXErr lyxerr;
236 # define CURRENT_POSITION __func__ ": "
238 # define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
241 #define LYXERR(type, msg) \
243 if (!lyx::lyxerr.debugging(type)) {} \
244 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
247 #define LYXERR_NOENDL(type, msg) \
249 if (!lyx::lyxerr.debugging(type)) {} \
250 else { lyx::lyxerr << CURRENT_POSITION << msg; } \
253 #define LYXERR_NOPOS(type, msg) \
255 if (!lyx::lyxerr.debugging(type)) {} \
256 else { lyx::lyxerr << msg; lyx::lyxerr.endl(); } \
259 #define LYXERR0(msg) \
261 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
265 /** Helper debug macro for quick and dirty logging. For example
267 * LYXERR0(_v_(var) << _v_(var + 1));
270 * Not a great typesetting, but it is handy in debugging sessions.
272 #define _v_(var) #var"=" << var << " "