summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Todd Stinson <stinson@lindenlab.com>2012-12-04 15:46:10 -0800
committerWilliam Todd Stinson <stinson@lindenlab.com>2012-12-04 15:46:10 -0800
commite2b5e11820cf234d035bdb07f4b145c397fdf67b (patch)
tree4147194fa9f652ede4d08e035cee3e3bdd88d872
parent1bfeddc0039c7a18cdd878c4fcc3a51529eb1019 (diff)
Implementing string conversion and comparison operator overrides for the LLMaterialID class.
-rw-r--r--indra/llprimitive/llmaterialid.cpp40
-rw-r--r--indra/llprimitive/llmaterialid.h9
-rw-r--r--indra/newview/llfloaterdebugmaterials.cpp52
-rw-r--r--indra/newview/llfloaterdebugmaterials.h2
4 files changed, 58 insertions, 45 deletions
diff --git a/indra/llprimitive/llmaterialid.cpp b/indra/llprimitive/llmaterialid.cpp
index 7df23e5ee0..5c810ddf12 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,6 +75,26 @@ bool LLMaterialID::operator != (const LLMaterialID& pOtherMaterialID) const
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);
+}
+
+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);
@@ -111,6 +135,22 @@ LLSD LLMaterialID::asLLSD() const
return materialID;
}
+std::string LLMaterialID::asString() const
+{
+ std::string materialID(reinterpret_cast<const char *>(get()), MATERIAL_ID_SIZE);
+ std::string materialIDString;
+ 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*>(&materialID.c_str()[i * sizeof(U32)]);
+ materialIDString += llformat("%08x", *value);
+ }
+ return materialIDString;
+}
+
void LLMaterialID::parseFromBinary (const LLSD::Binary& pMaterialID)
{
llassert(pMaterialID.size() == (MATERIAL_ID_SIZE * sizeof(U8)));
diff --git a/indra/llprimitive/llmaterialid.h b/indra/llprimitive/llmaterialid.h
index 1578172aec..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,6 +43,12 @@ public:
bool operator == (const LLMaterialID& pOtherMaterialID) const;
bool operator != (const LLMaterialID& pOtherMaterialID) const;
+
+ 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;
@@ -50,6 +58,7 @@ public:
void clear();
LLSD asLLSD() const;
+ std::string asString() const;
static const LLMaterialID null;
diff --git a/indra/newview/llfloaterdebugmaterials.cpp b/indra/newview/llfloaterdebugmaterials.cpp
index 3420665883..d5ed667c4d 100644
--- a/indra/newview/llfloaterdebugmaterials.cpp
+++ b/indra/newview/llfloaterdebugmaterials.cpp
@@ -1029,7 +1029,7 @@ void LLFloaterDebugMaterials::parseQueryViewableObjects()
rowParams.columns.add(cellParams);
cellParams.font = LLFontGL::getFontMonospace();
- std::string materialIDString = convertToPrintableMaterialID(objectMaterialID);
+ std::string materialIDString = objectMaterialID.asString();
cellParams.column = "material_id";
cellParams.value = materialIDString;
rowParams.columns.add(cellParams);
@@ -1090,8 +1090,9 @@ void LLFloaterDebugMaterials::parseGetResponse()
llassert(material.isMap());
llassert(material.has(MATERIALS_CAP_OBJECT_ID_FIELD));
llassert(material.get(MATERIALS_CAP_OBJECT_ID_FIELD).isBinary());
- const LLSD &materialID = material.get(MATERIALS_CAP_OBJECT_ID_FIELD);
- std::string materialIDString = convertToPrintableMaterialID(materialID);
+ const LLSD &materialIdLLSD = material.get(MATERIALS_CAP_OBJECT_ID_FIELD);
+ LLMaterialID materialID(materialIdLLSD);
+ std::string materialIDString = materialID.asString();
llassert(material.has(MATERIALS_CAP_MATERIAL_FIELD));
const LLSD &materialData = material.get(MATERIALS_CAP_MATERIAL_FIELD);
@@ -1311,7 +1312,8 @@ void LLFloaterDebugMaterials::parsePutResponse(const LLSD& pContent)
llassert(face.has(MATERIALS_CAP_MATERIAL_ID_FIELD));
llassert(face.get(MATERIALS_CAP_MATERIAL_ID_FIELD).isBinary());
- std::string materialIDString = convertToPrintableMaterialID(face.get(MATERIALS_CAP_MATERIAL_ID_FIELD));
+ LLMaterialID materialID(face.get(MATERIALS_CAP_MATERIAL_ID_FIELD));
+ std::string materialIDString = materialID.asString();
cellParams.font = LLFontGL::getFontMonospace();
@@ -1381,8 +1383,9 @@ void LLFloaterDebugMaterials::parsePostResponse(const LLSD& pMultiContent)
llassert(material.isMap());
llassert(material.has(MATERIALS_CAP_OBJECT_ID_FIELD));
llassert(material.get(MATERIALS_CAP_OBJECT_ID_FIELD).isBinary());
- const LLSD &materialID = material.get(MATERIALS_CAP_OBJECT_ID_FIELD);
- std::string materialIDString = convertToPrintableMaterialID(materialID);
+ const LLSD &materialIdLLSD = material.get(MATERIALS_CAP_OBJECT_ID_FIELD);
+ LLMaterialID materialID(materialIdLLSD);
+ std::string materialIDString = materialID.asString();
llassert(material.has(MATERIALS_CAP_MATERIAL_FIELD));
const LLSD &materialData = material.get(MATERIALS_CAP_MATERIAL_FIELD);
@@ -1787,43 +1790,6 @@ void LLFloaterDebugMaterials::updateControls()
}
}
-std::string LLFloaterDebugMaterials::convertToPrintableMaterialID(const LLSD& pBinaryHash) const
-{
- llassert(pBinaryHash.isBinary());
- const LLSD::Binary &materialIDValue = pBinaryHash.asBinary();
- unsigned int valueSize = materialIDValue.size();
-
- llassert(valueSize == 16);
- std::string materialID(reinterpret_cast<const char *>(&materialIDValue[0]), valueSize);
- std::string materialIDString;
- for (unsigned int i = 0U; i < (valueSize / 4); ++i)
- {
- if (i != 0U)
- {
- materialIDString += "-";
- }
- const U32 *value = reinterpret_cast<const U32*>(&materialID.c_str()[i * 4]);
- materialIDString += llformat("%08x", *value);
- }
- return materialIDString;
-}
-
-std::string LLFloaterDebugMaterials::convertToPrintableMaterialID(const LLMaterialID& pMaterialID) const
-{
- std::string materialID(reinterpret_cast<const char *>(pMaterialID.get()), 16);
- std::string materialIDString;
- for (unsigned int i = 0U; i < 4; ++i)
- {
- if (i != 0U)
- {
- materialIDString += "-";
- }
- const U32 *value = reinterpret_cast<const U32*>(&materialID.c_str()[i * 4]);
- materialIDString += llformat("%08x", *value);
- }
- return materialIDString;
-}
-
S32 LLFloaterDebugMaterials::getNormalMapOffsetX() const
{
return getLineEditorValue(mNormalMapOffsetX);
diff --git a/indra/newview/llfloaterdebugmaterials.h b/indra/newview/llfloaterdebugmaterials.h
index 565e440187..c5179ef6b0 100644
--- a/indra/newview/llfloaterdebugmaterials.h
+++ b/indra/newview/llfloaterdebugmaterials.h
@@ -133,8 +133,6 @@ private:
void updateStatusMessage();
void updateControls();
- std::string convertToPrintableMaterialID(const LLSD& pBinaryHash) const;
- std::string convertToPrintableMaterialID(const LLMaterialID& pMaterialID) const;
S32 getNormalMapOffsetX() const;
S32 getNormalMapOffsetY() const;