• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 #include <QtCore/QElapsedTimer>
00029 
00044 #if !defined(KDE_NO_DEBUG_OUTPUT)
00045 # if defined(QT_NO_DEBUG_OUTPUT) || defined(QT_NO_DEBUG_STREAM)
00046 #  define KDE_NO_DEBUG_OUTPUT
00047 # endif
00048 #endif
00049 
00050 #if !defined(KDE_NO_WARNING_OUTPUT)
00051 # if defined(QT_NO_WARNING_OUTPUT)
00052 #  define KDE_NO_WARNING_OUTPUT
00053 # endif
00054 #endif
00055 
00056 #ifdef QT_NO_DEBUG /* The application is compiled in release mode */
00057 # define KDE_DEBUG_ENABLED_BY_DEFAULT false
00058 #else
00059 # define KDE_DEBUG_ENABLED_BY_DEFAULT true
00060 #endif
00061 
00067 #define k_funcinfo ""
00068 
00076 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00077 
00082 KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0,
00083                                    int line = -1, const char *funcinfo = 0);
00084 
00089 KDECORE_EXPORT QDebug kDebugDevNull();
00090 
00095 KDECORE_EXPORT QString kRealBacktrace(int);
00096 
00097 
00107 #if !defined(KDE_NO_DEBUG_OUTPUT)
00108 inline QString kBacktrace(int levels=-1) { return kRealBacktrace(levels); }
00109 #else
00110 static inline QString kBacktrace(int=-1) { return QString(); }
00111 #endif
00112 
00118 KDECORE_EXPORT void kClearDebugConfig();
00119 
00120 #ifndef KDE_DEFAULT_DEBUG_AREA
00121 # define KDE_DEFAULT_DEBUG_AREA 0
00122 #endif
00123 
00145 #if !defined(KDE_NO_DEBUG_OUTPUT)
00146 
00152 static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA)
00153 { return kDebugStream(QtDebugMsg, area); }
00154 static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00155 { return cond ? kDebug(area) : kDebugDevNull(); }
00156 
00157 #else  // KDE_NO_DEBUG_OUTPUT
00158 static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00159 static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00160 #endif
00161 
00162 #if !defined(KDE_NO_WARNING_OUTPUT)
00163 
00169 static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA)
00170 { return kDebugStream(QtWarningMsg, area); }
00171 static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00172 { return cond ? kWarning(area) : kDebugDevNull(); }
00173 
00174 #else  // KDE_NO_WARNING_OUTPUT
00175 static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00176 static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
00177 #endif
00178 
00185 static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA)
00186 { return kDebugStream(QtCriticalMsg, area); }
00187 static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00188 { return cond ? kError(area) : kDebugDevNull(); }
00189 
00196 static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA)
00197 { return kDebugStream(QtFatalMsg, area); }
00198 static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00199 { return cond ? kFatal(area) : kDebugDevNull(); }
00200 
00201 struct KDebugTag { }; 
00202 typedef QDebug (*KDebugStreamFunction)(QDebug, KDebugTag); 
00203 inline QDebug operator<<(QDebug s, KDebugStreamFunction f)
00204 { return (*f)(s, KDebugTag()); }
00205 
00213 KDECORE_EXPORT QDebug perror(QDebug, KDebugTag);
00214 
00215 // operators for KDE types
00216 class KUrl;
00217 class KDateTime;
00218 class QObject;
00219 KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url);
00220 KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time);
00221 
00222 #if 1 || defined(KDE3_SUPPORT)
00223 #ifndef KDE_NO_DEPRECATED
00224 class KDE_DEPRECATED kndbgstream { };
00225 typedef QDebug kdbgstream;
00226 
00227 static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); }
00228 static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); }
00229 static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); }
00230 static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); }
00231 inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); }
00232 
00233 static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); }
00234 #endif
00235 #endif
00236 
00237 class WrongSyntax {};
00238 
00243 class KDebug                    //krazy= ?
00244 {
00245     const char *file;
00246     const char *funcinfo;
00247     int line;
00248     QtMsgType level;
00249 public:
00250     class Block;
00251     explicit inline KDebug(QtMsgType type, const char *f = 0, int l = -1, const char *info = 0)
00252         : file(f), funcinfo(info), line(l), level(type)
00253         {
00254 #ifdef KDE4_CMAKE_TOPLEVEL_DIR_LENGTH // set by FindKDE4Internal.cmake
00255             file = file + KDE4_CMAKE_TOPLEVEL_DIR_LENGTH + 1;
00256 #endif
00257         }
00258 
00259     inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA)
00260         { return kDebugStream(level, area, file, line, funcinfo); }
00261     inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
00262         { if (cond) return operator()(area); return kDebugDevNull(); }
00263 
00265     static KDECORE_EXPORT bool hasNullOutput(QtMsgType type,
00266                                              bool condition,
00267                                              int area,
00268                                              bool enableByDefault);
00269 
00271     static inline bool hasNullOutputQtDebugMsg(int area = KDE_DEFAULT_DEBUG_AREA)
00272         { return hasNullOutput(QtDebugMsg, true, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
00274     static inline bool hasNullOutputQtDebugMsg(bool condition, int area = KDE_DEFAULT_DEBUG_AREA)
00275         { return hasNullOutput(QtDebugMsg, condition, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
00276 
00299     static KDECORE_EXPORT int registerArea(const QByteArray& areaName, bool enabled = true);
00300 
00301 private:
00302     WrongSyntax operator()(const char*) {return WrongSyntax();} // error! Use kDebug() << "..." or kWarning() << "..." instead.
00303 };
00304 
00305 
00306 #if !defined(KDE_NO_DEBUG_OUTPUT)
00307 /* __VA_ARGS__ should work with any supported GCC version and MSVC > 2005 */
00308 # if defined(Q_CC_GNU) || (defined(Q_CC_MSVC) && _MSC_VER >= 1500)
00309 #  define kDebug(...) for (bool _k_kDebugDoOutput_ = !KDebug::hasNullOutputQtDebugMsg(__VA_ARGS__); \
00310                            KDE_ISUNLIKELY(_k_kDebugDoOutput_); _k_kDebugDoOutput_ = false) \
00311                            KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)(__VA_ARGS__)
00312 # else
00313 #  define kDebug     KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00314 # endif
00315 #else
00316 # define kDebug      while (false) kDebug
00317 #endif
00318 #if !defined(KDE_NO_WARNING_OUTPUT)
00319 # define kWarning    KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00320 #else
00321 # define kWarning    while (false) kWarning
00322 #endif
00323 
00324 #ifndef KDE_NO_DEBUG_OUTPUT
00325 
00351 class KDECORE_EXPORT KDebug::Block
00352 {
00353 public:
00354     Block(const char* label, int area = KDE_DEFAULT_DEBUG_AREA);
00355     ~Block();
00356 
00357 private:
00358     QElapsedTimer m_startTime;
00359     const char *m_label;
00360     int m_area;
00361     int m_color;
00362     class Private;
00363     Private* const d;
00364 };
00365 
00369 #define KDEBUG_BLOCK KDebug::Block _kDebugBlock(Q_FUNC_INFO);
00370 
00371 #else
00372 
00373 class KDECORE_EXPORT KDebug::Block
00374 {
00375 public:
00376     Block(const char*, int = KDE_DEFAULT_DEBUG_AREA) {}
00377     ~Block() {}
00378 };
00379 
00380 #define KDEBUG_BLOCK
00381 
00382 #endif
00383 
00389 #define KWARNING_NOTIMPLEMENTED kWarning() << "NOT-IMPLEMENTED";
00390 
00396 #define KWARNING_DEPRECATED kWarning() << "DEPRECATED";
00397 
00400 #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
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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