annotate base/Debug.h @ 1299:838a45cff62d 3.0-integration

Don't show this... We should find a better way to make it available in the UI
author Chris Cannam
date Fri, 25 Nov 2016 17:33:12 +0000
parents ad2d3e0a8b7c
children 166d7a4c2cd6
rev   line source
Chris@685 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@685 2
Chris@685 3 /*
Chris@685 4 Sonic Visualiser
Chris@685 5 An audio file viewer and annotation editor.
Chris@685 6 Centre for Digital Music, Queen Mary, University of London.
Chris@685 7 This file copyright 2010-2011 Chris Cannam and QMUL.
Chris@685 8
Chris@685 9 This program is free software; you can redistribute it and/or
Chris@685 10 modify it under the terms of the GNU General Public License as
Chris@685 11 published by the Free Software Foundation; either version 2 of the
Chris@685 12 License, or (at your option) any later version. See the file
Chris@685 13 COPYING included with this distribution for more information.
Chris@685 14 */
Chris@685 15
Chris@1061 16 #ifndef SV_DEBUG_H
Chris@1061 17 #define SV_DEBUG_H
Chris@685 18
Chris@685 19 #include <QDebug>
Chris@685 20 #include <QTextStream>
Chris@843 21
Chris@1042 22 #include "RealTime.h"
Chris@871 23
Chris@685 24 #include <string>
Chris@685 25 #include <iostream>
Chris@1061 26 #include <fstream>
Chris@685 27
Chris@685 28 class QString;
Chris@685 29 class QUrl;
Chris@685 30
Chris@685 31 QDebug &operator<<(QDebug &, const std::string &);
Chris@685 32 std::ostream &operator<<(std::ostream &, const QString &);
Chris@685 33 std::ostream &operator<<(std::ostream &, const QUrl &);
Chris@685 34
Chris@843 35 using std::cout;
Chris@843 36 using std::cerr;
Chris@843 37 using std::endl;
Chris@843 38
Chris@1061 39 class SVDebug {
Chris@1061 40 public:
Chris@1061 41 SVDebug();
Chris@1061 42 ~SVDebug();
Chris@1061 43
Chris@1061 44 template <typename T>
Chris@1061 45 inline SVDebug &operator<<(const T &t) {
Chris@1275 46 if (m_silenced) return *this;
Chris@1061 47 if (m_ok) {
Chris@1061 48 if (m_eol) {
Chris@1061 49 m_stream << m_prefix << " ";
Chris@1061 50 }
Chris@1061 51 m_stream << t;
Chris@1061 52 m_eol = false;
Chris@1061 53 }
Chris@1061 54 return *this;
Chris@1061 55 }
Chris@1061 56
Chris@1061 57 inline SVDebug &operator<<(QTextStreamFunction) {
Chris@1275 58 if (m_silenced) return *this;
Chris@1061 59 m_stream << std::endl;
Chris@1061 60 m_eol = true;
Chris@1061 61 return *this;
Chris@1061 62 }
Chris@1061 63
Chris@1275 64 static void silence() { m_silenced = true; }
Chris@1275 65
Chris@1061 66 private:
Chris@1061 67 std::fstream m_stream;
Chris@1061 68 char *m_prefix;
Chris@1061 69 bool m_ok;
Chris@1061 70 bool m_eol;
Chris@1275 71 static bool m_silenced;
Chris@1275 72 };
Chris@1275 73
Chris@1275 74 class SVCerr {
Chris@1275 75 public:
Chris@1275 76 SVCerr(SVDebug &d) : m_d(d) { }
Chris@1275 77
Chris@1275 78 template <typename T>
Chris@1275 79 inline SVCerr &operator<<(const T &t) {
Chris@1275 80 if (m_silenced) return *this;
Chris@1275 81 m_d << t;
Chris@1275 82 cerr << t;
Chris@1275 83 return *this;
Chris@1275 84 }
Chris@1275 85
Chris@1275 86 inline SVCerr &operator<<(QTextStreamFunction f) {
Chris@1275 87 if (m_silenced) return *this;
Chris@1275 88 m_d << f;
Chris@1275 89 cerr << std::endl;
Chris@1275 90 return *this;
Chris@1275 91 }
Chris@1275 92
Chris@1275 93 static void silence() { m_silenced = true; }
Chris@1275 94
Chris@1275 95 private:
Chris@1275 96 SVDebug &m_d;
Chris@1275 97 static bool m_silenced;
Chris@1061 98 };
Chris@1061 99
Chris@1061 100 extern SVDebug &getSVDebug();
Chris@1275 101 extern SVCerr &getSVCerr();
Chris@685 102
Chris@1275 103 // Writes to debug log only
Chris@690 104 #define SVDEBUG getSVDebug()
Chris@685 105
Chris@1275 106 // Writes to both SVDEBUG and cerr
Chris@1275 107 #define SVCERR getSVCerr()
Chris@1275 108
Chris@685 109 #endif /* !_DEBUG_H_ */
Chris@685 110