5 * FIXME: It would be nice if, in lyx::use_gui mode, instead of
6 * outputting to the console, we would pipe all messages onto a file
7 * and visualise the contents dynamically in a Qt window if needed.
9 * This file is part of LyX, the document processor.
10 * Licence details can be found in the file COPYING.
12 * \author Lars Gullik Bjønnes
13 * \author Jean-Marc Lasgouttes
16 * Full author contact details are available in file CREDITS.
22 #include "support/strfwd.h"
29 template<typename CharT, typename Traits> class basic_streambuf;
30 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 const std::vector<Type> levels();
113 /** A function to convert symbolic string names on debug levels
114 to their numerical value.
116 Type value(std::string const & val);
118 /// Return description of level
119 std::string const description(Type val);
121 /// Return name of level
122 std::string const name(Type val);
125 /** Display the tags and descriptions of the current debug level
128 void showLevel(std::ostream & os, Type level);
130 /** show all the possible tags that can be used for debugging */
131 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(): enabled_(true), second_used_(false) {}
146 /// Disable the stream completely
148 /// Enable the stream after a possible call of disable()
151 bool enabled() const { return enabled_; }
152 /// Returns true if t is part of the current debug level.
153 bool debugging(Debug::Type t = Debug::ANY) const;
157 void setStream(std::ostream & os) { stream_ = &os; }
159 std::ostream & stream() { return *stream_; }
160 /// Sets the debug level to t.
161 void level(Debug::Type t) { dt = t; }
162 /// Returns the current debug level.
163 Debug::Type level() const { return dt; }
165 operator std::ostream &() { return *stream_; }
166 /// Returns second_used_
167 bool second_used() { return second_used_; }
168 // Returns second stream
169 std::ostream & second() { return *second_; };
170 /// Sets the second stream
171 void setSecond(std::ostream * os) { second_used_ = (second_ = os); }
174 /// The current debug level
176 /// Is the stream enabled?
179 std::ostream * stream_;
180 /// Next stream for output duplication
181 std::ostream * second_;
182 /// Is the second stream enabled?
186 namespace support { class FileName; }
188 LyXErr & operator<<(LyXErr &, void const *);
189 LyXErr & operator<<(LyXErr &, char const *);
190 LyXErr & operator<<(LyXErr &, char);
191 LyXErr & operator<<(LyXErr &, int);
192 LyXErr & operator<<(LyXErr &, unsigned int);
193 LyXErr & operator<<(LyXErr &, long);
194 LyXErr & operator<<(LyXErr &, unsigned long);
195 LyXErr & operator<<(LyXErr &, double);
196 LyXErr & operator<<(LyXErr &, std::string const &);
197 LyXErr & operator<<(LyXErr &, docstring const &);
198 LyXErr & operator<<(LyXErr &, support::FileName const &);
199 LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
200 LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
202 extern LyXErr lyxerr;
206 #if USE_BOOST_CURRENT_FUNCTION
207 # include <boost/current_function.hpp>
208 # define CURRENT_POSITION BOOST_CURRENT_FUNCTION ": "
210 # define CURRENT_POSITION __FILE__ << "(" << __LINE__ << "): "
213 #define LYXERR(type, msg) \
215 if (!lyx::lyxerr.debugging(type)) {} \
216 else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
219 #define LYXERR0(msg) \
221 lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \