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 _LIBCPP_VERSION
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.
52 PARSER = (1 << 4), // 16
54 LYXRC = (1 << 5), // 32
56 KBMAP = (1 << 6), // 64
58 LATEX = (1 << 7), // 128
60 MATHED = (1 << 8), // 256 // Alejandro, please use this.
62 FONT = (1 << 9), // 512
64 TCLASS = (1 << 10), // 1024
66 LYXVC = (1 << 11), // 2048
68 LYXSERVER = (1 << 12), // 4096
70 UNDO = (1 << 13), // 8192
72 ACTION = (1 << 14), // 16384
84 INSETTEXT = (1 << 20),
94 SCROLLING = (1 << 25),
102 SELECTION = (1 << 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), enabled_(true), second_enabled_(false) {}
147 /// Disable the stream completely
149 /// Enable the stream after a possible call of disable()
156 std::ostream & stream() { return *stream_; }
158 operator std::ostream &() { return *stream_; }
160 void setStream(std::ostream & os) { stream_ = &os; }
161 /// Is the stream enabled ?
162 bool enabled() const { return enabled_; }
164 /// Returns second stream
165 std::ostream & secondStream() { return *second_stream_; }
166 /// Sets second stream
167 void setSecondStream(std::ostream * os)
168 { second_enabled_ = (second_stream_ = os); }
169 /// Is the second stream is enabled?
170 bool secondEnabled() { return second_enabled_; }
172 /// Sets the debug level
173 void setLevel(Debug::Type t) { dt_ = t; }
174 /// Returns the current debug level
175 Debug::Type level() const { return dt_; }
176 /// Returns true if t is part of the current debug level
177 bool debugging(Debug::Type t = Debug::ANY) const;
180 static char const * stripName(char const *);
183 /// The current debug level
186 std::ostream * stream_;
187 /// Is the stream enabled?
189 /// Next stream for output duplication
190 std::ostream * second_stream_;
191 /// Is the second stream enabled?
192 bool second_enabled_;
195 namespace support { class FileName; }
197 LyXErr & operator<<(LyXErr &, void const *);
198 LyXErr & operator<<(LyXErr &, char const *);
199 LyXErr & operator<<(LyXErr &, char);
200 LyXErr & operator<<(LyXErr &, int);
201 LyXErr & operator<<(LyXErr &, unsigned int);
202 LyXErr & operator<<(LyXErr &, long);
203 LyXErr & operator<<(LyXErr &, unsigned long);
204 LyXErr & operator<<(LyXErr &, double);
205 LyXErr & operator<<(LyXErr &, std::string const &);
206 LyXErr & operator<<(LyXErr &, docstring const &);
207 LyXErr & operator<<(LyXErr &, support::FileName const &);
208 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
209 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
211 extern LyXErr lyxerr;
215 #if USE_BOOST_CURRENT_FUNCTION
216 # include <boost/current_function.hpp>
217 # define CURRENT_POSITION BOOST_CURRENT_FUNCTION ": "
219 # define CURRENT_POSITION lyx::LyXErr::stripName(__FILE__) << " (" << __LINE__ << "): "
222 #define LYXERR(type, msg) \
224 if (!lyx::lyxerr.debugging(type)) {} \
225 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
228 #define LYXERR0(msg) \
230 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \