comparison base/Debug.h @ 1061:c1e43c8d2527 tonioni

Thread-local debug was causing crash on exit with Qt 5.4.x. But we introduced that because QDebug itself was crashing when used from multiple threads. Replace with simpler fstream version
author Chris Cannam
date Tue, 31 Mar 2015 10:36:52 +0100
parents 16dc7307d43a
children 8f076d02569a
comparison
equal deleted inserted replaced
1058:c49d52386cde 1061:c1e43c8d2527
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #ifndef _DEBUG_H_ 16 #ifndef SV_DEBUG_H
17 #define _DEBUG_H_ 17 #define SV_DEBUG_H
18 18
19 #include <QDebug> 19 #include <QDebug>
20 #include <QTextStream> 20 #include <QTextStream>
21 21
22 #include "RealTime.h" 22 #include "RealTime.h"
23 23
24 #include <string> 24 #include <string>
25 #include <iostream> 25 #include <iostream>
26 #include <fstream>
26 27
27 class QString; 28 class QString;
28 class QUrl; 29 class QUrl;
29 30
30 QDebug &operator<<(QDebug &, const std::string &); 31 QDebug &operator<<(QDebug &, const std::string &);
35 using std::cerr; 36 using std::cerr;
36 using std::endl; 37 using std::endl;
37 38
38 #ifndef NDEBUG 39 #ifndef NDEBUG
39 40
40 extern QDebug &getSVDebug(); 41 class SVDebug {
42 public:
43 SVDebug();
44 ~SVDebug();
45
46 template <typename T>
47 inline SVDebug &operator<<(const T &t) {
48 if (m_ok) {
49 if (m_eol) {
50 m_stream << m_prefix << " ";
51 }
52 m_stream << t;
53 m_eol = false;
54 }
55 return *this;
56 }
57
58 inline SVDebug &operator<<(QTextStreamFunction) {
59 m_stream << std::endl;
60 m_eol = true;
61 return *this;
62 }
63
64 private:
65 std::fstream m_stream;
66 char *m_prefix;
67 bool m_ok;
68 bool m_eol;
69 };
70
71 extern SVDebug &getSVDebug();
41 72
42 #define SVDEBUG getSVDebug() 73 #define SVDEBUG getSVDebug()
43
44 inline QDebug &operator<<(QDebug &d, const RealTime &rt) {
45 d << rt.toString();
46 return d;
47 }
48
49 inline QDebug &operator<<(QDebug &d, const Vamp::RealTime &rt) {
50 d << rt.toString();
51 return d;
52 }
53
54 template <typename T>
55 inline QDebug &operator<<(QDebug &d, const T &t) {
56 QString s;
57 QTextStream ts(&s);
58 ts << t;
59 d << s;
60 return d;
61 }
62 74
63 #else 75 #else
64 76
65 class NoDebug 77 class NoDebug
66 { 78 {