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;
37 /// This is all the different debug levels that we have.
44 INFO = (1u << 0), // 1
46 INIT = (1u << 1), // 2
52 PARSER = (1u << 4), // 16
54 LYXRC = (1u << 5), // 32
56 KBMAP = (1u << 6), // 64
58 LATEX = (1u << 7), // 128
60 MATHED = (1u << 8), // 256 // Alejandro, please use this.
62 FONT = (1u << 9), // 512
64 TCLASS = (1u << 10), // 1024
66 LYXVC = (1u << 11), // 2048
68 LYXSERVER = (1u << 12), // 4096
70 UNDO = (1u << 13), // 8192
72 ACTION = (1u << 14), // 16384
82 WORKAREA = (1u << 19),
84 CLIPBOARD = (1u << 20),
86 GRAPHICS = (1u << 21),
90 EXTERNAL = (1u << 23),
92 PAINTING = (1u << 24),
94 SCROLLING = (1u << 25),
102 SELECTION = (1u << 29),
111 /// Return number of levels
114 /// A function to convert debug level string names numerical values
115 Type value(std::string const & val);
117 /// A function to convert index of level to their numerical value
120 /// Return description of level
121 std::string const description(Type val);
123 /// Return name of level
124 std::string const name(Type val);
126 /// Display the tags and descriptions of the current debug level
127 void showLevel(std::ostream & os, Type level);
129 /// Show all the possible tags that can be used for debugging
130 void showTags(std::ostream & os);
136 inline void operator|=(Debug::Type & d1, Debug::Type d2)
138 d1 = static_cast<Debug::Type>(d1 | d2);
145 LyXErr(): dt_(Debug::NONE), stream_(0), enabled_(true),
146 second_stream_(0), second_enabled_(false) {}
148 /// Disable the stream completely
150 /// Enable the stream after a possible call of disable()
157 std::ostream & stream() { return *stream_; }
159 operator std::ostream &() { return *stream_; }
161 void setStream(std::ostream & os) { stream_ = &os; }
162 /// Is the stream enabled ?
163 bool enabled() const { return enabled_; }
165 /// Returns second stream
166 std::ostream & secondStream() { return *second_stream_; }
167 /// Sets second stream
168 void setSecondStream(std::ostream * os)
169 { second_enabled_ = (second_stream_ = os); }
170 /// Is the second stream is enabled?
171 bool secondEnabled() const { return second_enabled_; }
173 /// Sets the debug level
174 void setLevel(Debug::Type t) { dt_ = t; }
175 /// Returns the current debug level
176 Debug::Type level() const { return dt_; }
177 /// Returns true if t is part of the current debug level
178 bool debugging(Debug::Type t = Debug::ANY) const;
181 static char const * stripName(char const *);
184 /// The current debug level
187 std::ostream * stream_;
188 /// Is the stream enabled?
190 /// Next stream for output duplication
191 std::ostream * second_stream_;
192 /// Is the second stream enabled?
193 bool second_enabled_;
196 namespace support { class FileName; }
198 LyXErr & operator<<(LyXErr &, void const *);
199 LyXErr & operator<<(LyXErr &, char const *);
200 LyXErr & operator<<(LyXErr &, char);
201 LyXErr & operator<<(LyXErr &, int);
202 LyXErr & operator<<(LyXErr &, unsigned int);
203 LyXErr & operator<<(LyXErr &, long);
204 LyXErr & operator<<(LyXErr &, unsigned long);
205 #ifdef HAVE_LONG_LONG_INT
206 LyXErr & operator<<(LyXErr &, long long);
207 LyXErr & operator<<(LyXErr &, unsigned long long);
209 LyXErr & operator<<(LyXErr &, double);
210 LyXErr & operator<<(LyXErr &, std::string const &);
211 LyXErr & operator<<(LyXErr &, docstring const &);
212 LyXErr & operator<<(LyXErr &, support::FileName const &);
213 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
214 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
216 extern LyXErr lyxerr;
221 # define CURRENT_POSITION __func__ ": "
223 # define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
226 #define LYXERR(type, msg) \
228 if (!lyx::lyxerr.debugging(type)) {} \
229 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
232 #define LYXERR_NOENDL(type, msg) \
234 if (!lyx::lyxerr.debugging(type)) {} \
235 else { lyx::lyxerr << CURRENT_POSITION << msg; } \
238 #define LYXERR_NOPOS(type, msg) \
240 if (!lyx::lyxerr.debugging(type)) {} \
241 else { lyx::lyxerr << msg; lyx::lyxerr.endl(); } \
244 #define LYXERR0(msg) \
246 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \