]> git.tdb.fi Git - libs/gl.git/blob - source/core/predicate.cpp
Completely hide OpenGL from the public headers
[libs/gl.git] / source / core / predicate.cpp
1 #include <msp/strings/format.h>
2 #include "gl.h"
3 #include "predicate.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GL {
9
10 unsigned get_gl_predicate(Predicate pred)
11 {
12         switch(pred)
13         {
14         case NEVER: return GL_NEVER;
15         case ALWAYS: return GL_ALWAYS;
16         case LESS: return GL_LESS;
17         case LEQUAL: return GL_LEQUAL;
18         case EQUAL: return GL_EQUAL;
19         case GREATER: return GL_GREATER;
20         case GEQUAL: return GL_GEQUAL;
21         case NOTEQUAL: return GL_NOTEQUAL;
22         default: throw invalid_argument("get_gl_predicate");
23         }
24 }
25
26 void operator>>(const LexicalConverter &conv, Predicate &pred)
27 {
28         const string &str = conv.get();
29         if(str=="NEVER")
30                 pred = NEVER;
31         else if(str=="ALWAYS")
32                 pred = ALWAYS;
33         else if(str=="LESS")
34                 pred = LESS;
35         else if(str=="LEQUAL")
36                 pred = LEQUAL;
37         else if(str=="EQUAL")
38                 pred = EQUAL;
39         else if(str=="GREATER")
40                 pred = GREATER;
41         else if(str=="GEQUAL")
42                 pred = GEQUAL;
43         else if(str=="NOTEQUAL")
44                 pred = NOTEQUAL;
45         else
46                 throw lexical_error(format("conversion of '%s' to Predicate", str));
47 }
48
49 void operator<<(LexicalConverter &conv, Predicate pred)
50 {
51         switch(pred)
52         {
53         case NEVER: conv.result("NEVER"); break;
54         case ALWAYS: conv.result("ALWAYS"); break;
55         case LESS: conv.result("LESS"); break;
56         case LEQUAL: conv.result("LEQUAL"); break;
57         case EQUAL: conv.result("EQUAL"); break;
58         case GREATER: conv.result("GREATER"); break;
59         case GEQUAL: conv.result("GEQUAL"); break;
60         case NOTEQUAL: conv.result("NOTEQUAL"); break;
61         default: conv.result(format("Predicate(%#x)", static_cast<int>(pred))); break;
62         }
63 }
64
65 } // namespace GL
66 } // namespace Msp