]> git.tdb.fi Git - libs/gl.git/commitdiff
Use the lexical_cast framework instead of istreams
authorMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2011 20:55:35 +0000 (23:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 6 Sep 2011 20:55:35 +0000 (23:55 +0300)
source/pixelformat.cpp
source/pixelformat.h
source/primitivetype.cpp
source/primitivetype.h
source/texture.cpp
source/texture.h
source/vertexformat.h

index 8f742d83c38fcd012e0a46068eb96a0a350820aa..60fdc111e427c5e6ba563bfe0b849b1f4976537f 100644 (file)
@@ -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)
index d98b45f889e7df666ef2e87e9f56a4091fc412d4..dfe632b6c5f184870e9773dd5fad00b84af4ace1 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef MSP_GL_PIXELFORMAT_H_
 #define MSP_GL_PIXELFORMAT_H_
 
-#include <istream>
 #include <msp/graphics/pixelformat.h>
+#include <msp/strings/lexicalcast.h>
 #include "gl.h"
 #include <GL/glext.h>
 
@@ -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);
 
index 717d98358e993a356bffe1a7cdccdc409f3db829..7b47dfd852b927db1285bdb37fa27513c39682e0 100644 (file)
@@ -1,37 +1,33 @@
+#include <msp/strings/format.h>
 #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
index d004537b53a296632f5464785802eb041e2c9d73..52a6e8754f733c2273440a3dd42cd7c3736100cc 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MSP_GL_PRIMITIVETYPE_H_
 #define MSP_GL_PRIMITIVETYPE_H_
 
-#include <istream>
+#include <msp/strings/lexicalcast.h>
 #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
index d22f189bdcad4cc0a3c0e2f7edb0d55f30c5adaf..7ae1a2c2c5bda0e171e6f2ad171646afac48eab5 100644 (file)
@@ -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()));
 }
 
 
index 71fa34076cb46028c3ac7b440096ea8f9c1b6535..580517257e5ffc844808aea112d465929a5d2519 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef MSP_GL_TEXTURE_H_
 #define MSP_GL_TEXTURE_H_
 
-#include <istream>
 #include <msp/datafile/objectloader.h>
 #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
 {
index 2768e445df26809284e0076699eebc9fbc27762e..833b942ee82f2097bd004228879a43957fcd615d 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MSP_GL_VERTEXFORMAT_H_
 #define MSP_GL_VERTEXFORMAT_H_
 
-#include <istream>
+#include <msp/core/lexicalcast.h>
 
 namespace Msp {
 namespace GL {