diff Debug.h @ 67:146d14ab15e7

Debug output: off by default, on with VAMPY_VERBOSE environment variable
author Chris Cannam
date Mon, 17 Nov 2014 10:03:44 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Debug.h	Mon Nov 17 10:03:44 2014 +0000
@@ -0,0 +1,30 @@
+
+#ifndef DEBUG_H_INCLUDED
+#define DEBUG_H_INCLUDED
+
+#include <iostream>
+#include <cstdlib>
+
+class MyDebug
+{
+public:
+    MyDebug() : want(std::getenv("VAMPY_VERBOSE") != 0) { }
+
+    template <typename T>
+    MyDebug &operator<<(const T &t) {
+	if (want) std::cerr << t;
+        return *this;
+    }
+    
+    MyDebug &operator<<(std::ostream &(*o)(std::ostream &)) {
+	if (want) std::cerr << o;
+        return *this;
+    }
+    
+private:
+    bool want;
+};
+
+#define DSTREAM (MyDebug())
+
+#endif