• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

kdebug.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
00003                   2000-2002 Stephan Kulow (coolo@kde.org)
00004                   2002 Holger Freyther (freyther@kde.org)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
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 /* The application is compiled in release mode */
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 // operators for KDE types
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                    //krazy= ?
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 /* __VA_ARGS__ should work with any supported GCC version and MSVC > 2005 */
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

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal