]> git.tdb.fi Git - libs/gl.git/blobdiff - source/predicate.cpp
Add lexical conversions for BlendFactor and Predicate
[libs/gl.git] / source / predicate.cpp
diff --git a/source/predicate.cpp b/source/predicate.cpp
new file mode 100644 (file)
index 0000000..a195373
--- /dev/null
@@ -0,0 +1,49 @@
+#include <msp/strings/format.h>
+#include "predicate.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+void operator>>(const LexicalConverter &conv, Predicate &pred)
+{
+       const string &str = conv.get();
+       if(str=="NEVER")
+               pred = NEVER;
+       else if(str=="ALWAYS")
+               pred = ALWAYS;
+       else if(str=="LESS")
+               pred = LESS;
+       else if(str=="LEQUAL")
+               pred = LEQUAL;
+       else if(str=="EQUAL")
+               pred = EQUAL;
+       else if(str=="GREATER")
+               pred = GREATER;
+       else if(str=="GEQUAL")
+               pred = GEQUAL;
+       else if(str=="NOTEQUAL")
+               pred = NOTEQUAL;
+       else
+               throw lexical_error(format("conversion of '%s' to Predicate", str));
+}
+
+void operator<<(LexicalConverter &conv, Predicate pred)
+{
+       switch(pred)
+       {
+       case NEVER: conv.result("NEVER"); break;
+       case ALWAYS: conv.result("ALWAYS"); break;
+       case LESS: conv.result("LESS"); break;
+       case LEQUAL: conv.result("LEQUAL"); break;
+       case EQUAL: conv.result("EQUAL"); break;
+       case GREATER: conv.result("GREATER"); break;
+       case GEQUAL: conv.result("GEQUAL"); break;
+       case NOTEQUAL: conv.result("NOTEQUAL"); break;
+       default: conv.result(format("Predicate(%#x)", static_cast<int>(pred))); break;
+       }
+}
+
+} // namespace GL
+} // namespace Msp