Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualschupf

Posted 23 November 2012 - 07:25 AM

Thanks to all of you guys! I have chosen the custom key struct with operator<(). The extended string approach also would have worked, but the struct is more flexible.

@rip-off: I think your operator<() contains a bug. Assume these values for a and b: {52,30, "Foo"}, {50,40, "Foo"}
Your width has the highest priority, so operator<(a,b) should return false. But your operator< will return true, since a.width < b.width is false but a.height < b.height evaluates to true.

My struct looks like this (I hope its correct;)
struct TextureCacheID {
    std::string textureFilename;
    uint width, height;

    bool operator<(const TextureCacheID& rhs) const {
        return (textureFilename < rhs.textureFilename) || 
               ((textureFilename == rhs.textureFilename) && (width < rhs.width)) ||
               ((textureFilename == rhs.textureFilename) && (width == rhs.width) && (height < rhs.height));
    }
};


#3schupf

Posted 23 November 2012 - 07:25 AM

Thanks to all of you guys! I have chosen the custom key struct with operator<(). The extended string approach also would have worked, but the struct is more flexible.

@rip-off: I think your operator<() contains a bug. Assume these values for a and b: {52,30, "Foo"}, {50,40, "Foo"}
Your width has the highest priority, so operator<(a,b) should return false. But your operator< will return true, since a.width < b.width is false but a.height < b.height evaluates to true.

My struct looks like this (I hope its correct;)
struct TextureCacheID {
    std::string textureFilename;
    uint width, height;

    bool operator<(const TextureCacheID& rhs) const {
        return (textureFilename < rhs.textureFilename) || 
               ((textureFilename == rhs.textureFilename) && (width < rhs.width)) ||
               ((textureFilename == rhs.textureFilename) && (width == rhs.width) && (height < rhs.height));
    }
};


#2schupf

Posted 23 November 2012 - 07:25 AM

Thanks to all of you guys! I have chosen the custom key struct with operator<(). The extended string approach also would have worked, but the struct is more flexible.

@rip-off: I think your operator<() contains a bug. Assume these values for a and b: {52,30, "Foo"}, {50,40, "Foo"}
Your width has the highest priority, so operator<(a,b) should return false. But your operator< will return true, since a.width < b.width is false but a.height < b.height evaluates to true.

My struct looks like this (I hope its correct;)
struct TextureCacheID {
    std::string textureFilename;
    uint width, height;

    bool operator<(const TextureCacheID& rhs) const {
        return (textureFilename < rhs.textureFilename) || 
               ((textureFilename == rhs.textureFilename) && (width < rhs.width)) ||
               ((textureFilename == rhs.textureFilename) && (width == rhs.width) && (height < rhs.height));
    }
};


#1schupf

Posted 23 November 2012 - 07:13 AM

Thanks to all of you guys! I have chosen the custom key struct with operator<(). The extended string approach also would have worked, but the struct is more flexible.

PARTNERS