[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfdebug.h
Go to the documentation of this file.
1/***************************************************************************
2 * file klfdebug.h
3 * This file is part of the KLatexFormula Project.
4 * Copyright (C) 2011 by Philippe Faist
5 * philippe.faist at bluewin.ch
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22/* $Id$ */
23
24#ifndef KLFDEBUG_H
25#define KLFDEBUG_H
26
27#include <QMap>
28
29#include <klfdefs.h>
30
31// Note: function definitions are in klfdefs.cpp
32
33
34// DEBUG UTILITIES (SOME WITH TIME PRINTING FOR TIMING OPERATIONS)
35
37inline QByteArray klfShortFuncSignature(const char *fullFuncName)
38{ return klfShortFuncSignature(QByteArray(fullFuncName)); }
39
40KLF_EXPORT QString klfTimeOfDay(bool shortFmt = true);
41
42#define KLF_SHORT_TIME qPrintable(klfTimeOfDay())
43
44
46{
47public:
48 KLFDebugBlock(const QString& blockName);
49 KLFDebugBlock(bool printmsg, const QString& blockName);
50
51 virtual ~KLFDebugBlock();
52
53protected:
55private:
56 bool pPrintMsg;
57};
58
60{
61public:
62 KLFDebugBlockTimer(const QString& blockName);
63 virtual ~KLFDebugBlockTimer();
64};
65
66class KLFDebugObjectWatcherPrivate;
67
68class KLF_EXPORT KLFDebugObjectWatcher : public QObject
69{
70 Q_OBJECT
71public:
72 static KLFDebugObjectWatcher *getWatcher();
73
74 void registerObjectRefInfo(QObject *object, const QString& refInfo);
75public slots:
77 void debugObjectDestroyed(QObject *object);
78private:
79
82 static KLFDebugObjectWatcher *instance;
83
84 KLFDebugObjectWatcherPrivate *p;
85};
86
87
88// needed anyways for eg. KLF_ASSERT_CONDITION
89#include <QDebug>
90
91
92#ifdef KLF_DEBUG
93
94
96/* */ __klf_dbg_hdr(QDebug dbg, const char * funcname, const char *refinstance, const char * shorttime);
97
98template<class T>
99inline const T& __klf_debug_tee(const T& expr)
100{ qDebug()<<"TEE VALUE: "<<expr; return expr; }
101
102template<class T>
103inline const T& __klf_debug_tee2(const T& expr, QDebug dbg, const char *where, const char *what)
104/* NOTE: No ref-inst, because we would then have to provide both KLF_DEBUG_TEE() and KLF_DEBUG_TEE_ST()
105 * or similar, like klfDbgSt(). */
106{ __klf_dbg_hdr(dbg, where, NULL, NULL)<<"`"<<what<<"': "<<expr; return expr; }
107
108
109inline QString __klf_debug_ref_instance() { return QString(); }
110# define KLF_DEBUG_DECLARE_REF_INSTANCE( expr ) \
111 protected: inline QString __klf_debug_ref_instance() const { return QString("[")+ (expr) + "]" ; }
112
113# define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE() \
114 public: QString __klf_debug_this_ref_instance; \
115 protected: inline QString __klf_debug_ref_instance() const { return __klf_debug_this_ref_instance; }
116# define KLF_DEBUG_ASSIGN_REF_INSTANCE(object, ref_instance) \
117 (object)->__klf_debug_this_ref_instance = QString("[%1]").arg((ref_instance))
118# define KLF_DEBUG_ASSIGN_SAME_REF_INSTANCE(object) \
119 (object)->__klf_debug_this_ref_instance = __klf_debug_ref_instance();
120
121# define KLF_DEBUG_TIME_BLOCK(msg) KLFDebugBlockTimer __klf_debug_timer_block(QString("")+msg)
122# define KLF_DEBUG_BLOCK(msg) KLFDebugBlock __klf_debug_block(QString("")+msg)
123# define KLF_DEBUG_TEE(expr) \
124 __klf_debug_tee2(expr, qDebug(), KLF_FUNC_NAME, #expr)
125# define klfDebugf( arglist ) qDebug arglist
126# define klfDbg( streamableItems ) \
127 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, qPrintable(__klf_debug_ref_instance()), NULL) << streamableItems
128# define klfDbgT( streamableItems ) \
129 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, qPrintable(__klf_debug_ref_instance()), KLF_SHORT_TIME) << streamableItems
130# define klfDbgSt( streamableItems ) \
131 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, NULL, NULL) << streamableItems
132# define klfDbgStT( streamableItems ) \
133 __klf_dbg_hdr(qDebug(), KLF_FUNC_NAME, NULL, KLF_SHORT_TIME) << streamableItems
134
135# define KLF_DEBUG_WATCH_OBJECT( qobj ) \
136 { KLFDebugObjectWatcher::getWatcher()->registerObjectRefInfo((qobj), #qobj) ; \
137 connect((qobj), SIGNAL(destroyed()), \
138 KLFDebugObjectWatcher::getWatcher(), SLOT(debugObjectDestroyedFromSender())); \
139 }
140
141
142#else // KLF_DEBUG
143
144
145# define KLF_DEBUG_DECLARE_REF_INSTANCE( expr )
146# define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE()
147# define KLF_DEBUG_ASSIGN_REF_INSTANCE(object, ref_instance)
148# define KLF_DEBUG_ASSIGN_SAME_REF_INSTANCE(object)
149
150
151# define KLF_DEBUG_TIME_BLOCK(msg)
152# define KLF_DEBUG_BLOCK(msg)
153
154# define KLF_DEBUG_TEE(expr) (expr)
155
156# define klfDebugf(arglist)
157
158# define klfDbg( streamableItems )
159# define klfDbgT( streamableItems )
160# define klfDbgSt( streamableItems )
161# define klfDbgStT( streamableItems )
162
163# define KLF_DEBUG_WATCH_OBJECT( qobj )
164
165#endif // KLF_DEBUG
166
167
169/* */ __klf_warning_hdr(QDebug warnstr, const char * funcname, const char * shorttime);
170
171#define klfWarning(streamableItems) __klf_warning_hdr(qWarning(), KLF_FUNC_NAME, KLF_SHORT_TIME) << streamableItems
172
173
174/* Ensure a usable __func__ symbol */
175#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
176# if defined(__GNUC__) && __GNUC__ >= 2
177# define __func__ __FUNCTION__
178# else
179# define __func__ (qPrintable(QString("<in %2 line %1>").arg(__LINE__).arg(__FILE__)))
180# endif
181#endif
182/* The following declaration tests are inspired from "qglobal.h" in Qt 4.6.2 source code */
183#ifndef KLF_FUNC_NAME
184# if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) || defined(Q_CC_DIAB)
185# define KLF_FUNC_NAME (klfShortFuncSignature(__PRETTY_FUNCTION__).data())
186# elif defined(_MSC_VER)
187 /* MSVC 2002 doesn't have __FUNCSIG__ */
188# if _MSC_VER <= 1300
189# define KLF_FUNC_NAME __func__
190# else
191# define KLF_FUNC_NAME (klfShortFuncSignature(__FUNCSIG__).data())
192# endif
193# else
194# define KLF_FUNC_NAME __func__
195# endif
196#endif
197
198
199
200
201#define KLF_ASSERT_CONDITION(expr, msg, failaction) \
202 klfDbgSt("KLF_ASSERT_CONDITION(" #expr ")") ; \
203 if ( !(expr) ) { \
204 klfWarning(msg); \
205 failaction; \
206 }
207#define KLF_ASSERT_CONDITION_ELSE(expr, msg, failaction) \
208 KLF_ASSERT_CONDITION(expr, msg, failaction) \
209 else
210#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction) \
211 KLF_ASSERT_CONDITION((ptr) != NULL, msg, failaction)
212
213
214
215
216#endif
KLFDebugBlock(const QString &blockName)
Definition klfdefs.cpp:1066
QString pBlockName
Definition klfdebug.h:54
KLFDebugBlockTimer(const QString &blockName)
Definition klfdefs.cpp:1094
void registerObjectRefInfo(QObject *object, const QString &refInfo)
Definition klfdefs.cpp:945
void debugObjectDestroyed(QObject *object)
Definition klfdefs.cpp:959
static KLFDebugObjectWatcher * getWatcher()
Definition klfdefs.cpp:938
void debugObjectDestroyedFromSender()
Definition klfdebug.h:76
KLF_EXPORT QByteArray klfShortFuncSignature(const QByteArray &fullFuncName)
Definition klfdefs.cpp:975
KLF_EXPORT QDebug __klf_warning_hdr(QDebug warnstr, const char *funcname, const char *shorttime)
Definition klfdefs.cpp:1130
KLF_EXPORT QString klfTimeOfDay(bool shortFmt=true)
Definition klfdefs.cpp:1049
KLF_EXPORT QDebug __klf_dbg_hdr(QDebug dbg, const char *funcname, const char *refinstance, const char *shorttime)
Definition klfdefs.cpp:1120
Base declarations for klatexformula and some utilities.
#define KLF_EXPORT
Definition klfdefs.h:41
QObject(QObject *parent)
QObject * sender() const

Generated by doxygen 1.14.0