svcore  1.9
Debug.h
Go to the documentation of this file.
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 
22 #include <vamp-hostsdk/RealTime.h>
23 
24 #include <string>
25 #include <iostream>
26 
27 class QString;
28 class QUrl;
29 
30 QDebug &operator<<(QDebug &, const std::string &);
31 std::ostream &operator<<(std::ostream &, const QString &);
32 std::ostream &operator<<(std::ostream &, const QUrl &);
33 
34 using std::cout;
35 using std::cerr;
36 using std::endl;
37 
38 #ifndef NDEBUG
39 
40 extern QDebug &getSVDebug();
41 
42 #define SVDEBUG getSVDebug()
43 
44 inline QDebug &operator<<(QDebug &d, const Vamp::RealTime &rt) {
45  d << rt.toString();
46  return d;
47 }
48 
49 template <typename T>
50 inline QDebug &operator<<(QDebug &d, const T &t) {
51  QString s;
52  QTextStream ts(&s);
53  ts << t;
54  d << s;
55  return d;
56 }
57 
58 #else
59 
60 class NoDebug
61 {
62 public:
63  inline NoDebug() {}
64  inline ~NoDebug(){}
65 
66  template <typename T>
67  inline NoDebug &operator<<(const T &) { return *this; }
68 
69  inline NoDebug &operator<<(QTextStreamFunction) { return *this; }
70 };
71 
72 #define SVDEBUG NoDebug()
73 
74 #endif /* !NDEBUG */
75 
76 #endif /* !_DEBUG_H_ */
77 
QDebug & operator<<(QDebug &, const std::string &)
Definition: Debug.cpp:84
QDebug & getSVDebug()
Definition: Debug.cpp:36