From: Mikko Rasa Date: Tue, 6 Sep 2011 20:55:35 +0000 (+0300) Subject: Use the lexical_cast framework instead of istreams X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3d6188a7f48566398e7ad7548dbd47a68bc73bdc;p=libs%2Fgl.git Use the lexical_cast framework instead of istreams --- diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index 8f742d83..60fdc111 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -6,41 +6,36 @@ using namespace std; namespace Msp { namespace GL { -istream &operator>>(istream &in, PixelFormat &fmt) +void operator>>(const LexicalConverter &conv, PixelFormat &fmt) { - string word; - - in>>word; - if(word=="COLOR_INDEX") + if(conv.get()=="COLOR_INDEX") fmt = COLOR_INDEX; - else if(word=="STENCIL_INDEX") + else if(conv.get()=="STENCIL_INDEX") fmt = STENCIL_INDEX; - else if(word=="DEPTH_COMPONENT") + else if(conv.get()=="DEPTH_COMPONENT") fmt = DEPTH_COMPONENT; - else if(word=="RED") + else if(conv.get()=="RED") fmt = RED; - else if(word=="GREEN") + else if(conv.get()=="GREEN") fmt = GREEN; - else if(word=="BLUE") + else if(conv.get()=="BLUE") fmt = BLUE; - else if(word=="ALPHA") + else if(conv.get()=="ALPHA") fmt = ALPHA; - else if(word=="RGB") + else if(conv.get()=="RGB") fmt = RGB; - else if(word=="RGBA") + else if(conv.get()=="RGBA") fmt = RGBA; - else if(word=="BGR") + else if(conv.get()=="BGR") fmt = BGR; - else if(word=="BGRA") + else if(conv.get()=="BGRA") fmt = BGRA; - else if(word=="LUMINANCE") + else if(conv.get()=="LUMINANCE") fmt = LUMINANCE; - else if(word=="LUMINANCE_ALPHA") + else if(conv.get()=="LUMINANCE_ALPHA") fmt = LUMINANCE_ALPHA; else - in.setstate(ios_base::failbit); - - return in; + throw lexical_error(format("conversion of '%s' to PixelFormat", conv.get())); } PixelFormat pixelformat_from_graphics(Graphics::PixelFormat pf) diff --git a/source/pixelformat.h b/source/pixelformat.h index d98b45f8..dfe632b6 100644 --- a/source/pixelformat.h +++ b/source/pixelformat.h @@ -1,8 +1,8 @@ #ifndef MSP_GL_PIXELFORMAT_H_ #define MSP_GL_PIXELFORMAT_H_ -#include #include +#include #include "gl.h" #include @@ -38,7 +38,7 @@ enum PixelFormat LUMINANCE_ALPHA32F = GL_LUMINANCE_ALPHA32F_ARB, }; -std::istream &operator>>(std::istream &, PixelFormat &); +void operator>>(const LexicalConverter &, PixelFormat &); PixelFormat pixelformat_from_graphics(Graphics::PixelFormat); diff --git a/source/primitivetype.cpp b/source/primitivetype.cpp index 717d9835..7b47dfd8 100644 --- a/source/primitivetype.cpp +++ b/source/primitivetype.cpp @@ -1,37 +1,33 @@ +#include #include "primitivetype.h" namespace Msp { namespace GL { -std::istream &operator>>(std::istream &in, PrimitiveType &pt) +void operator>>(const LexicalConverter &conv, PrimitiveType &pt) { - std::string str; - in>>str; - - if(str=="POINTS") + if(conv.get()=="POINTS") pt = POINTS; - else if(str=="LINES") + else if(conv.get()=="LINES") pt = LINES; - else if(str=="LINE_LOOP") + else if(conv.get()=="LINE_LOOP") pt = LINE_LOOP; - else if(str=="LINE_STRIP") + else if(conv.get()=="LINE_STRIP") pt = LINE_STRIP; - else if(str=="TRIANGLES") + else if(conv.get()=="TRIANGLES") pt = TRIANGLES; - else if(str=="TRIANGLE_STRIP") + else if(conv.get()=="TRIANGLE_STRIP") pt = TRIANGLE_STRIP; - else if(str=="TRIANGLE_FAN") + else if(conv.get()=="TRIANGLE_FAN") pt = TRIANGLE_FAN; - else if(str=="QUADS") + else if(conv.get()=="QUADS") pt = QUADS; - else if(str=="QUAD_STRIP") + else if(conv.get()=="QUAD_STRIP") pt = QUAD_STRIP; - else if(str=="POLYGON") + else if(conv.get()=="POLYGON") pt = POLYGON; else - in.setstate(std::ios_base::failbit); - - return in; + throw lexical_error(format("conversion of '%s' to PrimitiveType", conv.get())); } } // namespace GL diff --git a/source/primitivetype.h b/source/primitivetype.h index d004537b..52a6e875 100644 --- a/source/primitivetype.h +++ b/source/primitivetype.h @@ -1,7 +1,7 @@ #ifndef MSP_GL_PRIMITIVETYPE_H_ #define MSP_GL_PRIMITIVETYPE_H_ -#include +#include #include "gl.h" namespace Msp { @@ -21,7 +21,7 @@ enum PrimitiveType POLYGON = GL_POLYGON }; -std::istream &operator>>(std::istream &in, PrimitiveType &pt); +void operator>>(const LexicalConverter &, PrimitiveType &); } // namespace GL } // namespace Msp diff --git a/source/texture.cpp b/source/texture.cpp index d22f189b..7ae1a2c2 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -8,27 +8,22 @@ using namespace std; namespace Msp { namespace GL { -istream &operator>>(istream &in, TextureFilter &tf) +void operator>>(const LexicalConverter &c, TextureFilter &tf) { - string str; - in>>str; - - if(str=="NEAREST") + if(c.get()=="NEAREST") tf = NEAREST; - else if(str=="LINEAR") + else if(c.get()=="LINEAR") tf = LINEAR; - else if(str=="NEAREST_MIPMAP_NEAREST") + else if(c.get()=="NEAREST_MIPMAP_NEAREST") tf = NEAREST_MIPMAP_NEAREST; - else if(str=="NEAREST_MIPMAP_LINEAR") + else if(c.get()=="NEAREST_MIPMAP_LINEAR") tf = NEAREST_MIPMAP_LINEAR; - else if(str=="LINEAR_MIPMAP_NEAREST") + else if(c.get()=="LINEAR_MIPMAP_NEAREST") tf = LINEAR_MIPMAP_NEAREST; - else if(str=="LINEAR_MIPMAP_LINEAR") + else if(c.get()=="LINEAR_MIPMAP_LINEAR") tf = LINEAR_MIPMAP_LINEAR; else - in.setstate(ios_base::failbit); - - return in; + throw lexical_error(format("conversion of '%s' to TextureFilter", c.get())); } diff --git a/source/texture.h b/source/texture.h index 71fa3407..58051725 100644 --- a/source/texture.h +++ b/source/texture.h @@ -1,7 +1,6 @@ #ifndef MSP_GL_TEXTURE_H_ #define MSP_GL_TEXTURE_H_ -#include #include #include "gl.h" #include "predicate.h" @@ -19,8 +18,6 @@ enum TextureFilter LINEAR_MIPMAP_LINEAR = GL_LINEAR_MIPMAP_LINEAR }; -std::istream &operator>>(std::istream &, TextureFilter &); - enum TextureWrap { diff --git a/source/vertexformat.h b/source/vertexformat.h index 2768e445..833b942e 100644 --- a/source/vertexformat.h +++ b/source/vertexformat.h @@ -1,7 +1,7 @@ #ifndef MSP_GL_VERTEXFORMAT_H_ #define MSP_GL_VERTEXFORMAT_H_ -#include +#include namespace Msp { namespace GL {