Mercurial > hg > svcore
comparison base/Debug.h @ 685:99222d4bfc78 debug-output
Add Debug class
author | Chris Cannam |
---|---|
date | Thu, 12 May 2011 16:56:08 +0100 |
parents | |
children | 1424aa29ae95 |
comparison
equal
deleted
inserted
replaced
682:bd527db65d20 | 685:99222d4bfc78 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2010-2011 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _DEBUG_H_ | |
17 #define _DEBUG_H_ | |
18 | |
19 #include <QDebug> | |
20 #include <QTextStream> | |
21 #include <string> | |
22 #include <iostream> | |
23 | |
24 class QString; | |
25 class QUrl; | |
26 | |
27 QDebug &operator<<(QDebug &, const std::string &); | |
28 std::ostream &operator<<(std::ostream &, const QString &); | |
29 std::ostream &operator<<(std::ostream &, const QUrl &); | |
30 | |
31 #ifndef NDEBUG | |
32 | |
33 extern QDebug &getSVDebug(); | |
34 | |
35 #define DEBUG getSVDebug() | |
36 | |
37 template <typename T> | |
38 inline QDebug &operator<<(QDebug &d, const T &t) { | |
39 QString s; | |
40 QTextStream ts(&s); | |
41 ts << t; | |
42 d << s; | |
43 return d; | |
44 } | |
45 | |
46 #else | |
47 | |
48 class NoDebug | |
49 { | |
50 public: | |
51 inline NoDebug() {} | |
52 inline ~NoDebug(){} | |
53 | |
54 template <typename T> | |
55 inline NoDebug &operator<<(const T &) { return *this; } | |
56 | |
57 inline NoDebug &operator<<(QTextStreamFunction) { return *this; } | |
58 }; | |
59 | |
60 #define DEBUG NoDebug() | |
61 | |
62 #endif /* !NDEBUG */ | |
63 | |
64 #endif /* !_DEBUG_H_ */ | |
65 |