KDECore
kdebug.h
Go to the documentation of this file.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
00038 #if !defined(KDE_NO_DEBUG_OUTPUT)
00039 # if defined(QT_NO_DEBUG) || defined(QT_NO_DEBUG_OUTPUT) || defined(QT_NO_DEBUG_STREAM)
00040 # define KDE_NO_DEBUG_OUTPUT
00041 # endif
00042 #endif
00043
00044 #if !defined(KDE_NO_WARNING_OUTPUT)
00045 # if defined(QT_NO_WARNING_OUTPUT)
00046 # define KDE_NO_WARNING_OUTPUT
00047 # endif
00048 #endif
00049
00050
00056 #define k_funcinfo ""
00057
00065 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00066
00071 KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0,
00072 int line = -1, const char *funcinfo = 0);
00073
00078 KDECORE_EXPORT QDebug kDebugDevNull();
00079
00084 KDECORE_EXPORT QString kRealBacktrace(int);
00085
00086
00096 #if !defined(KDE_NO_DEBUG_OUTPUT)
00097 inline QString kBacktrace(int levels=-1) { return kRealBacktrace(levels); }
00098 #else
00099 static inline QString kBacktrace(int=-1) { return QString(); }
00100 #endif
00101
00107 KDECORE_EXPORT void kClearDebugConfig();
00108
00109 #ifndef KDE_DEFAULT_DEBUG_AREA
00110 # define KDE_DEFAULT_DEBUG_AREA 0
00111 #endif
00112
00134 #if !defined(KDE_NO_DEBUG_OUTPUT)
00135
00141 static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA)
00142 { return kDebugStream(QtDebugMsg, area); }
00143 static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00144 { return cond ? kDebug(area) : kDebugDevNull(); }
00145
00146 #else // KDE_NO_DEBUG_OUTPUT
00147 static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00148 static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00149 #endif
00150
00151 #if !defined(KDE_NO_WARNING_OUTPUT)
00152
00158 static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA)
00159 { return kDebugStream(QtWarningMsg, area); }
00160 static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00161 { return cond ? kWarning(area) : kDebugDevNull(); }
00162
00163 #else // KDE_NO_WARNING_OUTPUT
00164 static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00165 static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00166 #endif
00167
00174 static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA)
00175 { return kDebugStream(QtCriticalMsg, area); }
00176 static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00177 { return cond ? kError(area) : kDebugDevNull(); }
00178
00185 static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA)
00186 { return kDebugStream(QtFatalMsg, area); }
00187 static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00188 { return cond ? kFatal(area) : kDebugDevNull(); }
00189
00190 struct KDebugTag { };
00191 typedef QDebug (*KDebugStreamFunction)(QDebug, KDebugTag);
00192 inline QDebug operator<<(QDebug s, KDebugStreamFunction f)
00193 { return (*f)(s, KDebugTag()); }
00194
00202 KDECORE_EXPORT QDebug perror(QDebug, KDebugTag);
00203
00204
00205 class KUrl;
00206 class KDateTime;
00207 class QObject;
00208 KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url);
00209 KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time);
00210
00211 #if 1 || defined(KDE3_SUPPORT)
00212 class KDE_DEPRECATED kndbgstream { };
00213 typedef QDebug kdbgstream;
00214
00215 static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); }
00216 static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); }
00217 static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); }
00218 static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); }
00219 inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); }
00220
00221 static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); }
00222 #endif
00223
00228 class KDebug
00229 {
00230 const char *file;
00231 const char *funcinfo;
00232 int line;
00233 QtMsgType level;
00234 public:
00235 explicit inline KDebug(QtMsgType type, const char *f = 0, int l = -1, const char *info = 0)
00236 : file(f), funcinfo(info), line(l), level(type)
00237 { }
00238 inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA)
00239 { return kDebugStream(level, area, file, line, funcinfo); }
00240 inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00241 { if (cond) return operator()(area); return kDebugDevNull(); }
00242 };
00243
00244 #if !defined(KDE_NO_DEBUG_OUTPUT)
00245 # define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00246 #else
00247 # define kDebug if (1); else kDebug
00248 #endif
00249 #if !defined(KDE_NO_WARNING_OUTPUT)
00250 # define kWarning KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00251 #else
00252 # define kWarning if (1); else kWarning
00253 #endif
00254
00257 #endif
00258