3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
14 #include "support/debug.h"
15 #include "support/gettext.h"
17 #include "support/convert.h"
18 #include "support/lstrings.h"
19 #include "support/FileName.h"
27 using support::ascii_lowercase;
28 using support::bformat;
29 using support::isStrInt;
44 ErrorItem errorTags[] = {
45 { Debug::NONE, "none", N_("No debugging message")},
46 { Debug::INFO, "info", N_("General information")},
47 { Debug::DEBUG, "debug", N_("Developers' general debug messages")},
48 { Debug::ANY, "any", N_("All debugging messages")}
52 int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
57 Debug::Type Debug::value(string const & val)
62 string::size_type const st = v.find(',');
63 string const tmp(ascii_lowercase(v.substr(0, st)));
68 l |= static_cast<Type>(convert<int>(tmp));
70 // Search for an explicit name
71 for (int i = 0 ; i < numErrorTags ; ++i)
72 if (tmp == errorTags[i].name) {
73 l |= errorTags[i].level;
76 if (st == string::npos) break;
83 void Debug::showLevel(ostream & os, Debug::Type level)
85 // Show what features are traced
86 for (int i = 0; i < numErrorTags ; ++i) {
87 if (errorTags[i].level != Debug::ANY
88 && errorTags[i].level != Debug::NONE
89 && errorTags[i].level & level) {
90 // avoid to_utf8(_(...)) re-entrance problem
91 docstring const s = _(errorTags[i].desc);
92 os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
93 from_utf8(errorTags[i].name), s))
101 void Debug::showTags(ostream & os)
103 for (int i = 0; i < numErrorTags ; ++i)
104 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
105 << setw(13) << errorTags[i].name
106 << " " << to_utf8(_(errorTags[i].desc)) << '\n';
111 void LyXErr::disable()
117 void LyXErr::enable()
123 bool LyXErr::debugging(Debug::Type t) const
131 stream() << std::endl;
135 LyXErr & operator<<(LyXErr & l, void const * t)
136 { l.stream() << t; return l; }
137 LyXErr & operator<<(LyXErr & l, char const * t)
138 { l.stream() << t; return l; }
139 LyXErr & operator<<(LyXErr & l, char t)
140 { l.stream() << t; return l; }
141 LyXErr & operator<<(LyXErr & l, int t)
142 { l.stream() << t; return l; }
143 LyXErr & operator<<(LyXErr & l, unsigned int t)
144 { l.stream() << t; return l; }
145 LyXErr & operator<<(LyXErr & l, long t)
146 { l.stream() << t; return l; }
147 LyXErr & operator<<(LyXErr & l, unsigned long t)
148 { l.stream() << t; return l; }
149 LyXErr & operator<<(LyXErr & l, double t)
150 { l.stream() << t; return l; }
151 LyXErr & operator<<(LyXErr & l, std::string const & t)
152 { l.stream() << t; return l; }
153 LyXErr & operator<<(LyXErr & l, docstring const & t)
154 { l.stream() << to_utf8(t); return l; }
155 LyXErr & operator<<(LyXErr & l, support::FileName const & t)
156 { l.stream() << t; return l; }
157 LyXErr & operator<<(LyXErr & l, std::ostream &(*t)(std::ostream &))
158 { l.stream() << t; return l; }
159 LyXErr & operator<<(LyXErr & l, std::ios_base &(*t)(std::ios_base &))
160 { l.stream() << t; return l; }