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
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
00057 #define k_funcinfo ""
00058
00066 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00067
00072 KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0,
00073 int line = -1, const char *funcinfo = 0);
00074
00079 KDECORE_EXPORT QDebug kDebugDevNull();
00080
00085 KDECORE_EXPORT QString kRealBacktrace(int);
00086
00087
00097 #if !defined(KDE_NO_DEBUG_OUTPUT)
00098 inline QString kBacktrace(int levels=-1) { return kRealBacktrace(levels); }
00099 #else
00100 static inline QString kBacktrace(int=-1) { return QString(); }
00101 #endif
00102
00108 KDECORE_EXPORT void kClearDebugConfig();
00109
00110 #ifndef KDE_DEFAULT_DEBUG_AREA
00111 # define KDE_DEFAULT_DEBUG_AREA 0
00112 #endif
00113
00135 #if !defined(KDE_NO_DEBUG_OUTPUT)
00136
00142 static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA)
00143 { return kDebugStream(QtDebugMsg, area); }
00144 static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00145 { return cond ? kDebug(area) : kDebugDevNull(); }
00146
00147 #else // KDE_NO_DEBUG_OUTPUT
00148 static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00149 static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00150 #endif
00151
00152 #if !defined(KDE_NO_WARNING_OUTPUT)
00153
00159 static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA)
00160 { return kDebugStream(QtWarningMsg, area); }
00161 static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00162 { return cond ? kWarning(area) : kDebugDevNull(); }
00163
00164 #else // KDE_NO_WARNING_OUTPUT
00165 static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00166 static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00167 #endif
00168
00175 static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA)
00176 { return kDebugStream(QtCriticalMsg, area); }
00177 static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00178 { return cond ? kError(area) : kDebugDevNull(); }
00179
00186 static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA)
00187 { return kDebugStream(QtFatalMsg, area); }
00188 static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00189 { return cond ? kFatal(area) : kDebugDevNull(); }
00190
00191 struct KDebugTag { };
00192 typedef QDebug (*KDebugStreamFunction)(QDebug, KDebugTag);
00193 inline QDebug operator<<(QDebug s, KDebugStreamFunction f)
00194 { return (*f)(s, KDebugTag()); }
00195
00203 KDECORE_EXPORT QDebug perror(QDebug, KDebugTag);
00204
00205
00206 class KUrl;
00207 class KDateTime;
00208 class QObject;
00209 KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url);
00210 KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time);
00211
00212 #if 1 || defined(KDE3_SUPPORT)
00213 class KDE_DEPRECATED kndbgstream { };
00214 typedef QDebug kdbgstream;
00215
00216 static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); }
00217 static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); }
00218 static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); }
00219 static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); }
00220 inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); }
00221
00222 static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); }
00223 #endif
00224
00229 class KDebug
00230 {
00231 const char *file;
00232 const char *funcinfo;
00233 int line;
00234 QtMsgType level;
00235 public:
00236 explicit inline KDebug(QtMsgType type, const char *f = 0, int l = -1, const char *info = 0)
00237 : file(f), funcinfo(info), line(l), level(type)
00238 { }
00239 inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA)
00240 { return kDebugStream(level, area, file, line, funcinfo); }
00241 inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00242 { if (cond) return operator()(area); return kDebugDevNull(); }
00243 };
00244
00245 #if !defined(KDE_NO_DEBUG_OUTPUT)
00246 # define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00247 #else
00248 # define kDebug if (1); else kDebug
00249 #endif
00250 #if !defined(KDE_NO_WARNING_OUTPUT)
00251 # define kWarning KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00252 #else
00253 # define kWarning if (1); else kWarning
00254 #endif
00255
00258 #endif
00259