summaryrefslogtreecommitdiff
path: root/indra/llprimitive/llmaterialid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llprimitive/llmaterialid.cpp')
-rw-r--r--indra/llprimitive/llmaterialid.cpp46
1 files changed, 37 insertions, 9 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;
}