add ostream handling to Tribool
authorGerd von Egidy <gerd.von.egidy@intra2net.com>
Fri, 10 Feb 2012 10:38:01 +0000 (11:38 +0100)
committerGerd von Egidy <gerd.von.egidy@intra2net.com>
Fri, 10 Feb 2012 10:38:01 +0000 (11:38 +0100)
src/tribool.hpp

index a6469ae..1cb722c 100644 (file)
@@ -27,6 +27,11 @@ on this file might be covered by the GNU General Public License.
  * overloading the comparison operators, we rolled our own class.
  */
 
+#ifndef __TRIBOOL_HPP
+#define __TRIBOOL_HPP
+
+#include <iostream>
+
 namespace I2n
 {
 
@@ -64,3 +69,25 @@ private:
 };
 
 }
+
+namespace std
+{
+
+// allow Tribools to be easily printed to ostreams
+template <class charT, class traits>
+inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& os,
+                                                     const I2n::Tribool& x)
+{
+    if (x == I2n::Tribool::False)
+        os << '0';
+    else if (x == I2n::Tribool::True)
+        os << '1';
+    else
+        os << '?';
+    
+    return os;
+}
+
+}
+
+#endif