diff options
Diffstat (limited to 'dep/g3dlite/source/GUniqueID.cpp')
-rw-r--r-- | dep/g3dlite/source/GUniqueID.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/dep/g3dlite/source/GUniqueID.cpp b/dep/g3dlite/source/GUniqueID.cpp index 84c853e0e31..7dcc3ccd254 100644 --- a/dep/g3dlite/source/GUniqueID.cpp +++ b/dep/g3dlite/source/GUniqueID.cpp @@ -8,8 +8,27 @@ #include "G3D/BinaryOutput.h" #include "G3D/TextOutput.h" #include "G3D/NetworkDevice.h" +#include "G3D/Any.h" namespace G3D { + +GUniqueID& GUniqueID::operator=(const Any& a) { + a.verifyName("GUniqueID"); + a.verifyType(Any::ARRAY); + a.verifySize(1); + std::string s = a[0]; + a.verify(s.length() == 16); + id = GUniqueID::fromString16(s); + return *this; +} + + +Any GUniqueID::toAny() const { + Any a(Any::ARRAY, "GUniqueID"); + a.append(toString16()); + return a; +} + void GUniqueID::serialize(BinaryOutput& b) const { b.writeUInt64(id); @@ -34,6 +53,33 @@ void GUniqueID::deserialize(TextInput& t) { } +GUniqueID GUniqueID::NONE(uint16 tag) { + GUniqueID i; + uint64 t = tag; + i.id = (t << 54); + return i; +} + + +std::string GUniqueID::toString16() const { + return format("%08x%08x", uint32(id >> 32), uint32(id & 0xFFFFFFFF)); +} + + +GUniqueID GUniqueID::fromString16(const std::string& s) { + if (s.length() != 16) { + debugAssertM(false, "Corrupt 16-character string"); + return GUniqueID(); + } + + uint32 high = 0, low = 0; + sscanf(s.c_str(), "%08x%08x", &high, &low); + GUniqueID i; + i.id = (uint64(high) << 32) | low; + return i; +} + + GUniqueID GUniqueID::create(uint16 tag) { static uint64 counter = 0; static uint64 systemID = 0; |