Mercurial > hg > svcore
diff base/Debug.h @ 1275:ad2d3e0a8b7c 3.0-integration
Add SVCERR and the ability to silence debug output (giving Sonic Annotator a --quiet mode)
author | Chris Cannam |
---|---|
date | Tue, 22 Nov 2016 16:39:17 +0000 |
parents | 8f076d02569a |
children | 166d7a4c2cd6 |
line wrap: on
line diff
--- a/base/Debug.h Mon Nov 21 17:08:02 2016 +0000 +++ b/base/Debug.h Tue Nov 22 16:39:17 2016 +0000 @@ -43,6 +43,7 @@ template <typename T> inline SVDebug &operator<<(const T &t) { + if (m_silenced) return *this; if (m_ok) { if (m_eol) { m_stream << m_prefix << " "; @@ -54,21 +55,56 @@ } inline SVDebug &operator<<(QTextStreamFunction) { + if (m_silenced) return *this; m_stream << std::endl; m_eol = true; return *this; } + static void silence() { m_silenced = true; } + private: std::fstream m_stream; char *m_prefix; bool m_ok; bool m_eol; + static bool m_silenced; +}; + +class SVCerr { +public: + SVCerr(SVDebug &d) : m_d(d) { } + + template <typename T> + inline SVCerr &operator<<(const T &t) { + if (m_silenced) return *this; + m_d << t; + cerr << t; + return *this; + } + + inline SVCerr &operator<<(QTextStreamFunction f) { + if (m_silenced) return *this; + m_d << f; + cerr << std::endl; + return *this; + } + + static void silence() { m_silenced = true; } + +private: + SVDebug &m_d; + static bool m_silenced; }; extern SVDebug &getSVDebug(); +extern SVCerr &getSVCerr(); +// Writes to debug log only #define SVDEBUG getSVDebug() +// Writes to both SVDEBUG and cerr +#define SVCERR getSVCerr() + #endif /* !_DEBUG_H_ */