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.
40 typedef uint64_t base_type;
41 enum Type : base_type {
45 INFO = (1u << 0), // 1
47 INIT = (1u << 1), // 2
53 PARSER = (1u << 4), // 16
55 LYXRC = (1u << 5), // 32
57 KBMAP = (1u << 6), // 64
59 OUTFILE = (1u << 7), // 128
61 MATHED = (1u << 8), // 256 // Alejandro, please use this.
63 FONT = (1u << 9), // 512
65 TCLASS = (1u << 10), // 1024
67 LYXVC = (1u << 11), // 2048
69 LYXSERVER = (1u << 12), // 4096
71 UNDO = (1u << 13), // 8192
73 ACTION = (1u << 14), // 16384
83 WORKAREA = (1u << 19),
85 CLIPBOARD = (1u << 20),
87 GRAPHICS = (1u << 21),
91 EXTERNAL = (1u << 23),
93 PAINTING = (1u << 24),
95 SCROLLING = (1u << 25),
103 SELECTION = (1u << 29),
107 FINDVERBOSE= (1u << 31),
114 /// Return number of levels
117 /// A function to convert debug level string names numerical values
118 Type value(std::string const & val);
120 /// Check the validity of debug level names
121 /// \return the first bad level name
122 std::string badValue(std::string const & val);
124 /// A function to convert index of level to their numerical value
127 /// Return description of level
128 std::string const description(Type val);
130 /// Return name of level
131 std::string const name(Type val);
133 /// Display the tags and descriptions of the current debug level
134 void showLevel(std::ostream & os, Type level);
136 /// Show all the possible tags that can be used for debugging
137 void showTags(std::ostream & os);
143 inline void operator|=(Debug::Type & d1, Debug::Type d2)
145 d1 = static_cast<Debug::Type>(d1 | d2);
152 LyXErr(): dt_(Debug::NONE), stream_(0), enabled_(true),
153 second_stream_(0), second_enabled_(false) {}
155 /// Disable the stream completely
157 /// Enable the stream after a possible call of disable()
164 std::ostream & stream() { return *stream_; }
166 operator std::ostream &() { return *stream_; }
168 void setStream(std::ostream & os) { stream_ = &os; }
169 /// Is the stream enabled ?
170 bool enabled() const { return enabled_; }
172 /// Returns second stream
173 std::ostream & secondStream() { return *second_stream_; }
174 /// Sets second stream
175 void setSecondStream(std::ostream * os)
176 { second_enabled_ = (second_stream_ = os); }
177 /// Is the second stream is enabled?
178 bool secondEnabled() const { return second_enabled_; }
180 /// Sets the debug level
181 void setLevel(Debug::Type t) { dt_ = t; }
182 /// Returns the current debug level
183 Debug::Type level() const { return dt_; }
184 /// Returns true if t is part of the current debug level
185 bool debugging(Debug::base_type t = Debug::ANY) const;
188 static char const * stripName(char const *);
191 /// The current debug level
194 std::ostream * stream_;
195 /// Is the stream enabled?
197 /// Next stream for output duplication
198 std::ostream * second_stream_;
199 /// Is the second stream enabled?
200 bool second_enabled_;
203 namespace support { class FileName; }
205 LyXErr & operator<<(LyXErr &, void const *);
206 LyXErr & operator<<(LyXErr &, char const *);
207 LyXErr & operator<<(LyXErr &, char);
208 LyXErr & operator<<(LyXErr &, int);
209 LyXErr & operator<<(LyXErr &, unsigned int);
210 LyXErr & operator<<(LyXErr &, long);
211 LyXErr & operator<<(LyXErr &, unsigned long);
212 #ifdef HAVE_LONG_LONG_INT
213 LyXErr & operator<<(LyXErr &, long long);
214 LyXErr & operator<<(LyXErr &, unsigned long long);
216 LyXErr & operator<<(LyXErr &, double);
217 LyXErr & operator<<(LyXErr &, std::string const &);
218 LyXErr & operator<<(LyXErr &, docstring const &);
219 LyXErr & operator<<(LyXErr &, support::FileName const &);
220 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
221 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
223 extern LyXErr lyxerr;
228 # define CURRENT_POSITION __func__ ": "
230 # define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
233 #define LYXERR(type, msg) \
235 if (!lyx::lyxerr.debugging(type)) {} \
236 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
239 #define LYXERR_NOENDL(type, msg) \
241 if (!lyx::lyxerr.debugging(type)) {} \
242 else { lyx::lyxerr << CURRENT_POSITION << msg; } \
245 #define LYXERR_NOPOS(type, msg) \
247 if (!lyx::lyxerr.debugging(type)) {} \
248 else { lyx::lyxerr << msg; lyx::lyxerr.endl(); } \
251 #define LYXERR0(msg) \
253 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \