From e2b5e11820cf234d035bdb07f4b145c397fdf67b Mon Sep 17 00:00:00 2001 From: William Todd Stinson Date: Tue, 4 Dec 2012 15:46:10 -0800 Subject: Implementing string conversion and comparison operator overrides for the LLMaterialID class. --- indra/llprimitive/llmaterialid.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'indra/llprimitive/llmaterialid.cpp') 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 + +#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(get()), MATERIAL_ID_SIZE); + std::string materialIDString; + for (unsigned int i = 0U; i < static_cast(MATERIAL_ID_SIZE / sizeof(U32)); ++i) + { + if (i != 0U) + { + materialIDString += "-"; + } + const U32 *value = reinterpret_cast(&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))); -- cgit v1.2.3