diff options
author | Kitty Barnett <develop@catznip.com> | 2012-12-17 00:09:01 +0100 |
---|---|---|
committer | Kitty Barnett <develop@catznip.com> | 2012-12-17 00:09:01 +0100 |
commit | 5824e60c595a3004ba24c250cad72a5eace8013f (patch) | |
tree | a3f6839f56c3b19b59eb3509423354ebd12d4814 /indra/llprimitive | |
parent | a18ea9d92923e331c0a3e179e126659e694b1c07 (diff) | |
parent | 74d3dc41fb7e24410ba052a9c5ce2867fbdb9c0a (diff) |
Merge with viewer-materials tip
Diffstat (limited to 'indra/llprimitive')
-rw-r--r-- | indra/llprimitive/llmaterialid.cpp | 46 | ||||
-rw-r--r-- | indra/llprimitive/llmaterialid.h | 9 |
2 files changed, 45 insertions, 10 deletions
diff --git a/indra/llprimitive/llmaterialid.cpp b/indra/llprimitive/llmaterialid.cpp index bbbbf0ced3..590f5cd91f 100644 --- a/indra/llprimitive/llmaterialid.cpp +++ b/indra/llprimitive/llmaterialid.cpp @@ -29,6 +29,10 @@ #include "llmaterialid.h" +#include <string> + +#include "llformat.h" + const LLMaterialID LLMaterialID::null; LLMaterialID::LLMaterialID() @@ -71,15 +75,30 @@ bool LLMaterialID::operator != (const LLMaterialID& pOtherMaterialID) const return (compareToOtherMaterialID(pOtherMaterialID) != 0); } -LLMaterialID& LLMaterialID::operator = (const LLMaterialID& pOtherMaterialID) +bool LLMaterialID::operator < (const LLMaterialID& pOtherMaterialID) const { - copyFromOtherMaterialID(pOtherMaterialID); - return (*this); + return (compareToOtherMaterialID(pOtherMaterialID) < 0); } -bool LLMaterialID::operator < (const LLMaterialID& pOtherMaterialID) const +bool LLMaterialID::operator <= (const LLMaterialID& pOtherMaterialID) const { - return (compareToOtherMaterialID(pOtherMaterialID) < 0); + return (compareToOtherMaterialID(pOtherMaterialID) <= 0); +} + +bool LLMaterialID::operator > (const LLMaterialID& pOtherMaterialID) const +{ + return (compareToOtherMaterialID(pOtherMaterialID) > 0); +} + +bool LLMaterialID::operator >= (const LLMaterialID& pOtherMaterialID) const +{ + return (compareToOtherMaterialID(pOtherMaterialID) >= 0); +} + +LLMaterialID& LLMaterialID::operator = (const LLMaterialID& pOtherMaterialID) +{ + copyFromOtherMaterialID(pOtherMaterialID); + return (*this); } bool LLMaterialID::isNull() const @@ -119,13 +138,13 @@ LLSD LLMaterialID::asLLSD() const std::string LLMaterialID::asString() const { std::string materialIDString; - for (unsigned int i = 0U; i < 4; ++i) + for (unsigned int i = 0U; i < static_cast<unsigned int>(MATERIAL_ID_SIZE / sizeof(U32)); ++i) { if (i != 0U) { materialIDString += "-"; } - const U32 *value = reinterpret_cast<const U32*>(&mID[i * 4]); + const U32 *value = reinterpret_cast<const U32*>(&get()[i * sizeof(U32)]); materialIDString += llformat("%08x", *value); } return materialIDString; @@ -139,10 +158,19 @@ void LLMaterialID::parseFromBinary (const LLSD::Binary& pMaterialID) void LLMaterialID::copyFromOtherMaterialID(const LLMaterialID& pOtherMaterialID) { - memcpy(mID, pOtherMaterialID.mID, MATERIAL_ID_SIZE * sizeof(U8)); + memcpy(mID, pOtherMaterialID.get(), MATERIAL_ID_SIZE * sizeof(U8)); } int LLMaterialID::compareToOtherMaterialID(const LLMaterialID& pOtherMaterialID) const { - return memcmp(mID, pOtherMaterialID.mID, MATERIAL_ID_SIZE * sizeof(U8)); + int retVal = 0; + + for (unsigned int i = 0U; (retVal == 0) && (i < static_cast<unsigned int>(MATERIAL_ID_SIZE / sizeof(U32))); ++i) + { + const U32 *thisValue = reinterpret_cast<const U32*>(&get()[i * sizeof(U32)]); + const U32 *otherValue = reinterpret_cast<const U32*>(&pOtherMaterialID.get()[i * sizeof(U32)]); + retVal = ((*thisValue < *otherValue) ? -1 : ((*thisValue > *otherValue) ? 1 : 0)); + } + + return retVal; } diff --git a/indra/llprimitive/llmaterialid.h b/indra/llprimitive/llmaterialid.h index ffefc9f11c..9db4065302 100644 --- a/indra/llprimitive/llmaterialid.h +++ b/indra/llprimitive/llmaterialid.h @@ -29,6 +29,8 @@ #define MATERIAL_ID_SIZE 16 +#include <string> + class LLMaterialID { public: @@ -41,8 +43,13 @@ public: bool operator == (const LLMaterialID& pOtherMaterialID) const; bool operator != (const LLMaterialID& pOtherMaterialID) const; - LLMaterialID& operator = (const LLMaterialID& pOtherMaterialID); + bool operator < (const LLMaterialID& pOtherMaterialID) const; + bool operator <= (const LLMaterialID& pOtherMaterialID) const; + bool operator > (const LLMaterialID& pOtherMaterialID) const; + bool operator >= (const LLMaterialID& pOtherMaterialID) const; + + LLMaterialID& operator = (const LLMaterialID& pOtherMaterialID); bool isNull() const; |