00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _KDEBUG_H_
00023 #define _KDEBUG_H_
00024
00025 #include <kdecore_export.h>
00026
00027 #include <QtCore/QDebug>
00028
00039 #if !defined(KDE_NO_DEBUG_OUTPUT)
00040 # if defined(QT_NO_DEBUG_OUTPUT) || defined(QT_NO_DEBUG_STREAM)
00041 # define KDE_NO_DEBUG_OUTPUT
00042 # endif
00043 #endif
00044
00045 #if !defined(KDE_NO_WARNING_OUTPUT)
00046 # if defined(QT_NO_WARNING_OUTPUT)
00047 # define KDE_NO_WARNING_OUTPUT
00048 # endif
00049 #endif
00050
00051 #ifdef QT_NO_DEBUG
00052 # define KDE_DEBUG_ENABLED_BY_DEFAULT false
00053 #else
00054 # define KDE_DEBUG_ENABLED_BY_DEFAULT true
00055 #endif
00056
00062 #define k_funcinfo ""
00063
00071 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00072
00077 KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0,
00078 int line = -1, const char *funcinfo = 0);
00079
00084 KDECORE_EXPORT QDebug kDebugDevNull();
00085
00090 KDECORE_EXPORT QString kRealBacktrace(int);
00091
00092
00102 #if !defined(KDE_NO_DEBUG_OUTPUT)
00103 inline QString kBacktrace(int levels=-1) { return kRealBacktrace(levels); }
00104 #else
00105 static inline QString kBacktrace(int=-1) { return QString(); }
00106 #endif
00107
00113 KDECORE_EXPORT void kClearDebugConfig();
00114
00115 #ifndef KDE_DEFAULT_DEBUG_AREA
00116 # define KDE_DEFAULT_DEBUG_AREA 0
00117 #endif
00118
00140 #if !defined(KDE_NO_DEBUG_OUTPUT)
00141
00147 static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA)
00148 { return kDebugStream(QtDebugMsg, area); }
00149 static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00150 { return cond ? kDebug(area) : kDebugDevNull(); }
00151
00152 #else // KDE_NO_DEBUG_OUTPUT
00153 static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00154 static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00155 #endif
00156
00157 #if !defined(KDE_NO_WARNING_OUTPUT)
00158
00164 static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA)
00165 { return kDebugStream(QtWarningMsg, area); }
00166 static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00167 { return cond ? kWarning(area) : kDebugDevNull(); }
00168
00169 #else // KDE_NO_WARNING_OUTPUT
00170 static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00171 static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00172 #endif
00173
00180 static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA)
00181 { return kDebugStream(QtCriticalMsg, area); }
00182 static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00183 { return cond ? kError(area) : kDebugDevNull(); }
00184
00191 static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA)
00192 { return kDebugStream(QtFatalMsg, area); }
00193 static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00194 { return cond ? kFatal(area) : kDebugDevNull(); }
00195
00196 struct KDebugTag { };
00197 typedef QDebug (*KDebugStreamFunction)(QDebug, KDebugTag);
00198 inline QDebug operator<<(QDebug s, KDebugStreamFunction f)
00199 { return (*f)(s, KDebugTag()); }
00200
00208 KDECORE_EXPORT QDebug perror(QDebug, KDebugTag);
00209
00210
00211 class KUrl;
00212 class KDateTime;
00213 class QObject;
00214 KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url);
00215 KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time);
00216
00217 #if 1 || defined(KDE3_SUPPORT)
00218 class KDE_DEPRECATED kndbgstream { };
00219 typedef QDebug kdbgstream;
00220
00221 static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); }
00222 static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); }
00223 static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); }
00224 static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); }
00225 inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); }
00226
00227 static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); }
00228 #endif
00229
00234 class KDebug
00235 {
00236 const char *file;
00237 const char *funcinfo;
00238 int line;
00239 QtMsgType level;
00240 public:
00241 explicit inline KDebug(QtMsgType type, const char *f = 0, int l = -1, const char *info = 0)
00242 : file(f), funcinfo(info), line(l), level(type)
00243 { }
00244
00245 inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA)
00246 { return kDebugStream(level, area, file, line, funcinfo); }
00247 inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00248 { if (cond) return operator()(area); return kDebugDevNull(); }
00249
00250 #if 1 // TODO: remove before 4.4 is released
00252 static KDECORE_EXPORT bool hasNullOutput(QtMsgType type,
00253 int area);
00255 static KDECORE_EXPORT bool hasNullOutput(QtMsgType type, bool condition,
00256 int area);
00257 #endif
00258
00260 static KDECORE_EXPORT bool hasNullOutput(QtMsgType type,
00261 bool condition,
00262 int area,
00263 bool enableByDefault);
00264
00266 static inline bool hasNullOutputQtDebugMsg(int area = KDE_DEFAULT_DEBUG_AREA)
00267 { return hasNullOutput(QtDebugMsg, true, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
00269 static inline bool hasNullOutputQtDebugMsg(bool condition, int area = KDE_DEFAULT_DEBUG_AREA)
00270 { return hasNullOutput(QtDebugMsg, condition, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
00271
00294 static KDECORE_EXPORT int registerArea(const QByteArray& areaName, bool enabled = true);
00295 };
00296
00297
00298 #if !defined(KDE_NO_DEBUG_OUTPUT)
00299
00300 # if defined(Q_CC_GNU) || (defined(Q_CC_MSVC) && _MSC_VER >= 1500)
00301 # define kDebug(...) for (bool _k_kDebugDoOutput_ = !KDebug::hasNullOutputQtDebugMsg(__VA_ARGS__); \
00302 KDE_ISUNLIKELY(_k_kDebugDoOutput_); _k_kDebugDoOutput_ = false) \
00303 KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)(__VA_ARGS__)
00304 # else
00305 # define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00306 # endif
00307 #else
00308 # define kDebug while (false) kDebug
00309 #endif
00310 #if !defined(KDE_NO_WARNING_OUTPUT)
00311 # define kWarning KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00312 #else
00313 # define kWarning while (false) kWarning
00314 #endif
00315
00318 #endif