aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/tribool.cc
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/util/tribool.cc')
-rw-r--r--paludis/util/tribool.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/paludis/util/tribool.cc b/paludis/util/tribool.cc
index 9b639c664..b1bcf16ea 100644
--- a/paludis/util/tribool.cc
+++ b/paludis/util/tribool.cc
@@ -18,6 +18,11 @@
*/
#include <paludis/util/tribool.hh>
+#include <paludis/util/exception.hh>
+#include <paludis/util/stringify.hh>
+#include <string>
+#include <istream>
+#include <ostream>
using namespace paludis;
@@ -60,3 +65,49 @@ paludis::indeterminate(const NoType<0u> * const)
return 0;
}
+std::ostream &
+paludis::operator<< (std::ostream & s, const Tribool v)
+{
+ if (v.is_true())
+ s << "true";
+ else if (v.is_false())
+ s << "false";
+ else if (v.is_indeterminate())
+ s << "indeterminate";
+ else
+ throw InternalError(PALUDIS_HERE, "Bad tribool");
+ return s;
+}
+
+std::istream &
+paludis::operator>> (std::istream & s, Tribool & a)
+{
+ std::string value;
+ s >> value;
+
+ do
+ {
+ if (value == "true")
+ {
+ a = true;
+ break;
+ }
+
+ if (value == "false")
+ {
+ a = false;
+ break;
+ }
+
+ if (value == "indeterminate")
+ {
+ a = indeterminate;
+ break;
+ }
+
+ s.setstate(std::ios::badbit);
+ } while (false);
+
+ return s;
+}
+