]> git.tdb.fi Git - libs/gl.git/commitdiff
Turn VertexFormat into a class and hide the data member
authorMikko Rasa <tdb@tdb.fi>
Sun, 2 Sep 2012 14:29:02 +0000 (17:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 2 Sep 2012 14:29:02 +0000 (17:29 +0300)
Outsiders have no need to access it directly

source/vertexformat.cpp
source/vertexformat.h

index 02410857bff6e8873570055499b4be71800a6c02..65b276baa7115e5c5482fc0b39ac0a1ed4f85cb4 100644 (file)
@@ -50,41 +50,9 @@ VertexFormat::~VertexFormat()
        delete[] data;
 }
 
-unsigned VertexFormat::stride() const
-{
-       unsigned s = 0;
-       for(const unsigned char *i=begin(); i!=end(); ++i)
-               s += get_component_size(*i);
-       return s;
-}
-
-int VertexFormat::offset(VertexComponent comp, unsigned index) const
-{
-       if((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=8) || index>=53)
-               throw out_of_range("VertexFormat::offset");
-
-       unsigned type = get_component_type(comp)+index;
-       unsigned size = get_component_size(comp);
-       unsigned offs = 0;
-       for(const unsigned char *i=begin(); i!=end(); ++i)
-       {
-               if(get_component_type(*i)==type)
-               {
-                       if(get_component_size(*i)>=size)
-                               return offs;
-                       else
-                               return -1;
-               }
-               else
-                       offs += get_component_size(*i);
-       }
-
-       return -1;
-}
-
-VertexFormat operator,(const VertexFormat &f, VertexComponent c)
+VertexFormat VertexFormat::operator,(VertexComponent c) const
 {
-       VertexFormat r = f;
+       VertexFormat r = *this;
        if(r.data)
        {
                const unsigned char n = ++r.data[0];
@@ -107,11 +75,11 @@ VertexFormat operator,(const VertexFormat &f, VertexComponent c)
        return r;
 }
 
-VertexFormat operator,(const VertexFormat &f, unsigned i)
+VertexFormat VertexFormat::operator,(unsigned i) const
 {
-       if(!f.data)
+       if(!data)
                throw invalid_operation("VertexFormat::operator,");
-       VertexFormat r = f;
+       VertexFormat r = *this;
        unsigned char *c = r.data+r.data[0];
        if((*c<TEXCOORD1 && i>0) || (*c<ATTRIB1 && i>=8) || i>=53)
                throw invalid_argument("VertexFormat::operator,");
@@ -120,6 +88,38 @@ VertexFormat operator,(const VertexFormat &f, unsigned i)
        return r;
 }
 
+unsigned VertexFormat::stride() const
+{
+       unsigned s = 0;
+       for(const unsigned char *i=begin(); i!=end(); ++i)
+               s += get_component_size(*i);
+       return s;
+}
+
+int VertexFormat::offset(VertexComponent comp, unsigned index) const
+{
+       if((comp<TEXCOORD1 && index>0) || (comp<ATTRIB1 && index>=8) || index>=53)
+               throw out_of_range("VertexFormat::offset");
+
+       unsigned type = get_component_type(comp)+index;
+       unsigned size = get_component_size(comp);
+       unsigned offs = 0;
+       for(const unsigned char *i=begin(); i!=end(); ++i)
+       {
+               if(get_component_type(*i)==type)
+               {
+                       if(get_component_size(*i)>=size)
+                               return offs;
+                       else
+                               return -1;
+               }
+               else
+                       offs += get_component_size(*i);
+       }
+
+       return -1;
+}
+
 void operator>>(const LexicalConverter &conv, VertexComponent &c)
 {
        const string &str = conv.get();
index 35b5de3d15d9910da9ffda9bb15d521c112d1f91..fb47484b35940b7e873b6d2586d333df0edda802 100644 (file)
@@ -25,16 +25,21 @@ enum VertexComponent
        ATTRIB4
 };
 
-struct VertexFormat
+class VertexFormat
 {
+private:
        unsigned char *data;
 
+public:
        VertexFormat();
        VertexFormat(VertexComponent);
        VertexFormat(const VertexFormat &);
        VertexFormat &operator=(const VertexFormat &);
        ~VertexFormat();
 
+       VertexFormat operator,(VertexComponent c) const;
+       VertexFormat operator,(unsigned i) const;
+
        bool empty() const { return !data || !data[0]; }
        const unsigned char *begin() const { return data ? data+1 : 0; }
        const unsigned char *end() const { return data ? data+1+data[0] : 0; }
@@ -42,11 +47,9 @@ struct VertexFormat
        int offset(VertexComponent, unsigned = 0) const;
 };
 
-VertexFormat operator,(const VertexFormat &f, VertexComponent c);
 inline VertexFormat operator,(VertexComponent c1, VertexComponent c2)
 { return (VertexFormat(c1), c2); }
 
-VertexFormat operator,(const VertexFormat &f, unsigned i);
 inline VertexFormat operator,(VertexComponent c, unsigned i)
 { return (VertexFormat(c), i); }