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 /// Check the validity of debug level names
118 /// \return the first bad level name
119 std::string badValue(std::string const & val);
121 /// A function to convert index of level to their numerical value
124 /// Return description of level
125 std::string const description(Type val);
127 /// Return name of level
128 std::string const name(Type val);
130 /// Display the tags and descriptions of the current debug level
131 void showLevel(std::ostream & os, Type level);
133 /// Show all the possible tags that can be used for debugging
134 void showTags(std::ostream & os);
140 inline void operator|=(Debug::Type & d1, Debug::Type d2)
142 d1 = static_cast<Debug::Type>(d1 | d2);
149 LyXErr(): dt_(Debug::NONE), stream_(0), enabled_(true),
150 second_stream_(0), second_enabled_(false) {}
152 /// Disable the stream completely
154 /// Enable the stream after a possible call of disable()
161 std::ostream & stream() { return *stream_; }
163 operator std::ostream &() { return *stream_; }
165 void setStream(std::ostream & os) { stream_ = &os; }
166 /// Is the stream enabled ?
167 bool enabled() const { return enabled_; }
169 /// Returns second stream
170 std::ostream & secondStream() { return *second_stream_; }
171 /// Sets second stream
172 void setSecondStream(std::ostream * os)
173 { second_enabled_ = (second_stream_ = os); }
174 /// Is the second stream is enabled?
175 bool secondEnabled() const { return second_enabled_; }
177 /// Sets the debug level
178 void setLevel(Debug::Type t) { dt_ = t; }
179 /// Returns the current debug level
180 Debug::Type level() const { return dt_; }
181 /// Returns true if t is part of the current debug level
182 bool debugging(Debug::Type t = Debug::ANY) const;
185 static char const * stripName(char const *);
188 /// The current debug level
191 std::ostream * stream_;
192 /// Is the stream enabled?
194 /// Next stream for output duplication
195 std::ostream * second_stream_;
196 /// Is the second stream enabled?
197 bool second_enabled_;
200 namespace support { class FileName; }
202 LyXErr & operator<<(LyXErr &, void const *);
203 LyXErr & operator<<(LyXErr &, char const *);
204 LyXErr & operator<<(LyXErr &, char);
205 LyXErr & operator<<(LyXErr &, int);
206 LyXErr & operator<<(LyXErr &, unsigned int);
207 LyXErr & operator<<(LyXErr &, long);
208 LyXErr & operator<<(LyXErr &, unsigned long);
209 #ifdef HAVE_LONG_LONG_INT
210 LyXErr & operator<<(LyXErr &, long long);
211 LyXErr & operator<<(LyXErr &, unsigned long long);
213 LyXErr & operator<<(LyXErr &, double);
214 LyXErr & operator<<(LyXErr &, std::string const &);
215 LyXErr & operator<<(LyXErr &, docstring const &);
216 LyXErr & operator<<(LyXErr &, support::FileName const &);
217 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
218 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
220 extern LyXErr lyxerr;
225 # define CURRENT_POSITION __func__ ": "
227 # define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
230 #define LYXERR(type, msg) \
232 if (!lyx::lyxerr.debugging(type)) {} \
233 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
236 #define LYXERR_NOENDL(type, msg) \
238 if (!lyx::lyxerr.debugging(type)) {} \
239 else { lyx::lyxerr << CURRENT_POSITION << msg; } \
242 #define LYXERR_NOPOS(type, msg) \
244 if (!lyx::lyxerr.debugging(type)) {} \
245 else { lyx::lyxerr << msg; lyx::lyxerr.endl(); } \
248 #define LYXERR0(msg) \
250 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \