• 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 
00302     static KDECORE_EXPORT int registerArea(const QByteArray& areaName, bool enabled = true);
00303 
00304 private:
00305     WrongSyntax operator()(const char*) {return WrongSyntax();} // error! Use kDebug() << "..." or kWarning() << "..." instead.
00306 };
00307 
00308 
00309 #if !defined(KDE_NO_DEBUG_OUTPUT)
00310 /* __VA_ARGS__ should work with any supported GCC version and MSVC > 2005 */
00311 # if defined(Q_CC_GNU) || (defined(Q_CC_MSVC) && _MSC_VER >= 1500)
00312 #  define kDebug(...) for (bool _k_kDebugDoOutput_ = !KDebug::hasNullOutputQtDebugMsg(__VA_ARGS__); \
00313                            KDE_ISUNLIKELY(_k_kDebugDoOutput_); _k_kDebugDoOutput_ = false) \
00314                            KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)(__VA_ARGS__)
00315 # else
00316 #  define kDebug     KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00317 # endif
00318 #else
00319 # define kDebug      while (false) kDebug
00320 #endif
00321 #if !defined(KDE_NO_WARNING_OUTPUT)
00322 # define kWarning    KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO)
00323 #else
00324 # define kWarning    while (false) kWarning
00325 #endif
00326 
00327 #ifndef KDE_NO_DEBUG_OUTPUT
00328 
00354 class KDECORE_EXPORT KDebug::Block
00355 {
00356 public:
00357     Block(const char* label, int area = KDE_DEFAULT_DEBUG_AREA);
00358     ~Block();
00359 
00360 private:
00361     QElapsedTimer m_startTime;
00362     const char *m_label;
00363     int m_area;
00364     int m_color;
00365     class Private;
00366     Private* const d;
00367 };
00368 
00372 #define KDEBUG_BLOCK KDebug::Block _kDebugBlock(Q_FUNC_INFO);
00373 
00374 #else
00375 
00376 class KDECORE_EXPORT KDebug::Block
00377 {
00378 public:
00379     Block(const char*, int = KDE_DEFAULT_DEBUG_AREA) {}
00380     ~Block() {}
00381 };
00382 
00383 #define KDEBUG_BLOCK
00384 
00385 #endif
00386 
00392 #define KWARNING_NOTIMPLEMENTED kWarning() << "NOT-IMPLEMENTED";
00393 
00399 #define KWARNING_DEPRECATED kWarning() << "DEPRECATED";
00400 
00403 #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