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
134 std::string const name(Type val);
136 /// Display the tags and descriptions of the current debug level
137 void showLevel(std::ostream & os, Type level);
139 /// Show all the possible tags that can be used for debugging
140 void showTags(std::ostream & os);
146 inline void operator|=(Debug::Type & d1, Debug::Type d2)
148 d1 = static_cast<Debug::Type>(d1 | d2);
155 LyXErr(): dt_(Debug::NONE), stream_(0), enabled_(true),
156 second_stream_(0), second_enabled_(false) {}
158 /// Disable the stream completely
160 /// Enable the stream after a possible call of disable()
167 std::ostream & stream() { return *stream_; }
169 operator std::ostream &() { return *stream_; }
171 void setStream(std::ostream & os) { stream_ = &os; }
172 /// Is the stream enabled ?
173 bool enabled() const { return enabled_; }
175 /// Returns second stream
176 std::ostream & secondStream() { return *second_stream_; }
177 /// Sets second stream
178 void setSecondStream(std::ostream * os)
179 { second_enabled_ = (second_stream_ = os); }
180 /// Is the second stream is enabled?
181 bool secondEnabled() const { return second_enabled_; }
183 /// Sets the debug level
184 void setLevel(Debug::Type t) { dt_ = t; }
185 /// Returns the current debug level
186 Debug::Type level() const { return dt_; }
187 /// Returns true if t is part of the current debug level
188 bool debugging(Debug::base_type t = Debug::ANY) const;
191 static char const * stripName(char const *);
194 /// The current debug level
197 std::ostream * stream_;
198 /// Is the stream enabled?
200 /// Next stream for output duplication
201 std::ostream * second_stream_;
202 /// Is the second stream enabled?
203 bool second_enabled_;
206 namespace support { class FileName; }
208 LyXErr & operator<<(LyXErr &, void const *);
209 LyXErr & operator<<(LyXErr &, char const *);
210 LyXErr & operator<<(LyXErr &, char);
211 LyXErr & operator<<(LyXErr &, int);
212 LyXErr & operator<<(LyXErr &, unsigned int);
213 LyXErr & operator<<(LyXErr &, long);
214 LyXErr & operator<<(LyXErr &, unsigned long);
215 #ifdef HAVE_LONG_LONG_INT
216 LyXErr & operator<<(LyXErr &, long long);
217 LyXErr & operator<<(LyXErr &, unsigned long long);
219 LyXErr & operator<<(LyXErr &, double);
220 LyXErr & operator<<(LyXErr &, std::string const &);
221 LyXErr & operator<<(LyXErr &, docstring const &);
222 LyXErr & operator<<(LyXErr &, support::FileName const &);
223 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
224 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
226 extern LyXErr lyxerr;
231 # define CURRENT_POSITION __func__ ": "
233 # define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
236 #define LYXERR(type, msg) \
238 if (!lyx::lyxerr.debugging(type)) {} \
239 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
242 #define LYXERR_NOENDL(type, msg) \
244 if (!lyx::lyxerr.debugging(type)) {} \
245 else { lyx::lyxerr << CURRENT_POSITION << msg; } \
248 #define LYXERR_NOPOS(type, msg) \
250 if (!lyx::lyxerr.debugging(type)) {} \
251 else { lyx::lyxerr << msg; lyx::lyxerr.endl(); } \
254 #define LYXERR0(msg) \
256 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \