00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KLFDEBUG_H
00025 #define KLFDEBUG_H
00026
00027 #include <qmap.h>
00028
00029 #include <klfdefs.h>
00030
00031
00032
00033
00034
00035
00036
00037 KLF_EXPORT QByteArray klfShortFuncSignature(const QByteArray& fullFuncName);
00038 inline QByteArray klfShortFuncSignature(const char *fullFuncName)
00039 #ifdef KLFBACKEND_QT4
00040 { return klfShortFuncSignature(QByteArray(fullFuncName)); }
00041 #else
00042 { return klfShortFuncSignature(QByteArray().duplicate(fullFuncName, strlen(fullFuncName))); }
00043 #endif
00044
00045 KLF_EXPORT QString klfTimeOfDay(bool shortFmt = true);
00046
00047 #ifdef KLFBACKEND_QT4
00048 # define KLF_SHORT_TIME qPrintable(klfTimeOfDay())
00049 #else
00050 # define KLF_SHORT_TIME (klfTimeOfDay().ascii())
00051 #endif
00052
00053
00054 class KLF_EXPORT KLFDebugBlock
00055 {
00056 public:
00057 KLFDebugBlock(const QString& blockName);
00058 KLFDebugBlock(bool printmsg, const QString& blockName);
00059
00060 virtual ~KLFDebugBlock();
00061
00062 protected:
00063 QString pBlockName;
00064 private:
00065 bool pPrintMsg;
00066 };
00067
00068 class KLF_EXPORT KLFDebugBlockTimer : public KLFDebugBlock
00069 {
00070 public:
00071 KLFDebugBlockTimer(const QString& blockName);
00072 virtual ~KLFDebugBlockTimer();
00073 };
00074
00075 #ifndef KLFBACKEND_QT4
00076 class KLF_EXPORT __klf_dbg_string_obj {
00077 QString hdr;
00078 public:
00079 __klf_dbg_string_obj(const QString& h) : hdr(h) { }
00080 __klf_dbg_string_obj(const __klf_dbg_string_obj& other) : hdr(other.hdr) { }
00081 int operator=(const QString& msg);
00082 };
00083 #endif
00084
00085 class KLFDebugObjectWatcherPrivate;
00086
00087 class KLF_EXPORT KLFDebugObjectWatcher : public QObject
00088 {
00089 Q_OBJECT
00090 public:
00091 static KLFDebugObjectWatcher *getWatcher();
00092
00093 void registerObjectRefInfo(QObject *object, const QString& refInfo);
00094 public slots:
00095 void debugObjectDestroyedFromSender() { debugObjectDestroyed(const_cast<QObject*>(sender())); }
00096 void debugObjectDestroyed(QObject *object);
00097 private:
00098
00099 KLFDebugObjectWatcher();
00100 virtual ~KLFDebugObjectWatcher();
00101 static KLFDebugObjectWatcher *instance;
00102
00103 KLFDebugObjectWatcherPrivate *p;
00104 };
00105
00106
00107 #ifdef KLFBACKEND_QT4
00108 # include <QDebug>
00109 #endif
00110
00111 #ifdef KLF_DEBUG
00112
00113 template<class T>
00114 inline const T& __klf_debug_tee(const T& expr)
00115 # ifdef KLFBACKEND_QT4
00116 { qDebug()<<"TEE VALUE: "<<expr; return expr; }
00117 # else
00118 { return expr; }
00119 # endif
00120
00121
00122 # ifdef KLFBACKEND_QT4
00123 KLF_EXPORT QDebug
00124 __klf_dbg_hdr(QDebug dbg, const char * funcname, const char *refinstance, const char * shorttime);
00125 # else
00126 KLF_EXPORT __klf_dbg_string_obj
00127 __klf_dbg_hdr_qt3(const char *funcname, const char *refinstance, const char *shorttime) ;
00128 # endif
00129
00130 inline QString __klf_debug_ref_instance() { return QString(); }
00131 # define KLF_DEBUG_DECLARE_REF_INSTANCE( expr ) \
00132 protected: inline QString __klf_debug_ref_instance() const { return QString("[")+ (expr) + "]" ; }
00133
00134 # define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE() \
00135 public: QString __klf_debug_this_ref_instance; \
00136 protected: inline QString __klf_debug_ref_instance() const { return __klf_debug_this_ref_instance; }
00137 # define KLF_DEBUG_ASSIGN_REF_INSTANCE(object, ref_instance) \
00138 (object)->__klf_debug_this_ref_instance = QString("[%1]").arg((ref_instance))
00139 # define KLF_DEBUG_ASSIGN_SAME_REF_INSTANCE(object) \
00140 (object)->__klf_debug_this_ref_instance = __klf_debug_ref_instance();
00141
00142 # define KLF_DEBUG_TIME_BLOCK(msg) KLFDebugBlockTimer __klf_debug_timer_block(QString("")+msg)
00143 # define KLF_DEBUG_BLOCK(msg) KLFDebugBlock __klf_debug_block(QString("")+msg)
00144 # define KLF_DEBUG_TEE(expr) __klf_debug_tee(expr)
00145 # ifdef KLFBACKEND_QT4
00146 # define klfDbg( streamableItems ) \
00147 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, qPrintable(__klf_debug_ref_instance()), NULL) << streamableItems
00148 # define klfDbgT( streamableItems ) \
00149 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, qPrintable(__klf_debug_ref_instance()), KLF_SHORT_TIME) << streamableItems
00150 # define klfDbgSt( streamableItems ) \
00151 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, NULL, NULL) << streamableItems
00152 # define klfDbgStT( streamableItems ) \
00153 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, NULL, KLF_SHORT_TIME) << streamableItems
00154 # else
00155 # define klfDbg( string ) \
00156 __klf_dbg_hdr_qt3(KLF_FUNC_NAME, __klf_debug_ref_instance().local8Bit(), NULL) = QString("") + (string)
00157 # define klfDbgT( string ) \
00158 __klf_dbg_hdr_qt3(KLF_FUNC_NAME, __klf_debug_ref_instance().local8Bit(), KLF_SHORT_TIME) = QString("") + (string)
00159 # define klfDbgSt( string ) \
00160 __klf_dbg_hdr_qt3(KLF_FUNC_NAME, NULL, NULL) = QString("") + (string)
00161 # define klfDbgStT( string ) \
00162 __klf_dbg_hdr_qt3(KLF_FUNC_NAME, NULL, KLF_SHORT_TIME) = QString("") + (string)
00163 # endif
00164
00165 # define KLF_DEBUG_WATCH_OBJECT( qobj ) \
00166 { KLFDebugObjectWatcher::getWatcher()->registerObjectRefInfo((qobj), #qobj) ; \
00167 connect((qobj), SIGNAL(destroyed()), \
00168 KLFDebugObjectWatcher::getWatcher(), SLOT(debugObjectDestroyedFromSender())); \
00169 }
00170
00171
00172 #else // KLF_DEBUG
00173
00174
00175
00176 # define KLF_DEBUG_DECLARE_REF_INSTANCE( expr )
00177 # define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE()
00178 # define KLF_DEBUG_ASSIGN_REF_INSTANCE(object, ref_instance)
00179 # define KLF_DEBUG_ASSIGN_SAME_REF_INSTANCE(object)
00180
00181
00182 # define KLF_DEBUG_TIME_BLOCK(msg)
00183 # define KLF_DEBUG_BLOCK(msg)
00184
00185 # define KLF_DEBUG_TEE(expr) (expr)
00186
00187 # define klfDbg( streamableItems )
00188 # define klfDbgT( streamableItems )
00189 # define klfDbgSt( streamableItems )
00190 # define klfDbgStT( streamableItems )
00191
00192 # define KLF_DEBUG_WATCH_OBJECT( qobj )
00193
00194 #endif // KLF_DEBUG
00195
00196
00197
00198
00199 #if defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
00200 # if defined(__GNUC__) && __GNUC__ >= 2
00201 # define __func__ __FUNCTION__
00202 # else
00203 # ifdef KLFBACKEND_QT4
00204 # define __func__ (qPrintable(QString("<in %2 line %1>").arg(__LINE__).arg(__FILE__)))
00205 # else
00206 # define __func__ (QString("<in %2 line %1>").arg(__LINE__).arg(__FILE__).ascii().data())
00207 # endif
00208 # endif
00209 #endif
00210
00211 #ifndef KLF_FUNC_NAME
00212 # if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) || defined(Q_CC_DIAB)
00213 # define KLF_FUNC_NAME (klfShortFuncSignature(__PRETTY_FUNCTION__).data())
00214 # elif defined(_MSC_VER)
00215
00216 # if _MSC_VER <= 1300
00217 # define KLF_FUNC_NAME __func__
00218 # else
00219 # define KLF_FUNC_NAME (klfShortFuncSignature(__FUNCSIG__).data())
00220 # endif
00221 # else
00222 # define KLF_FUNC_NAME __func__
00223 # endif
00224 #endif
00225
00226
00227
00228
00229 #ifdef KLFBACKEND_QT4
00230 #define KLF_ASSERT_CONDITION(expr, msg, failaction) \
00231 if ( !(expr) ) { \
00232 qWarning().nospace()<<"In function "<<KLF_FUNC_NAME<<":\n\t"<<msg; \
00233 failaction; \
00234 }
00235 #else
00236 #define KLF_ASSERT_CONDITION(expr, msg, failaction) \
00237 if ( !(expr) ) { \
00238 qWarning("In function %s:\n\t%s", KLF_FUNC_NAME, (QString("")+msg).local8Bit().data()); \
00239 failaction; \
00240 }
00241 #endif
00242 #define KLF_ASSERT_CONDITION_ELSE(expr, msg, failaction) \
00243 KLF_ASSERT_CONDITION(expr, msg, failaction) \
00244 else
00245 #define KLF_ASSERT_NOT_NULL(ptr, msg, failaction) \
00246 KLF_ASSERT_CONDITION((ptr) != NULL, msg, failaction)
00247
00248
00249
00250
00251 #if defined(KLFBACKEND_QT4) && defined(QT_NO_DEBUG_OUTPUT)
00252
00253 inline QDebug& operator<<(QDebug& str, const QVariant& v) { return str; }
00254 #endif
00255
00256
00257
00258
00259
00260 #endif