diff options
| author | Vincent-Michael <Vincent_Michael@gmx.de> | 2014-08-23 16:41:54 +0200 |
|---|---|---|
| committer | Vincent-Michael <Vincent_Michael@gmx.de> | 2014-08-23 16:41:54 +0200 |
| commit | 4a29c73403c4dc713a8a31cb96289adff2b910c1 (patch) | |
| tree | de0c6b191031bac7fb2764edb2a81382a331f81c /dep/g3dlite/source/GUniqueID.cpp | |
| parent | b90329d63acaecb1f074dd2b303561baa9f639a2 (diff) | |
| parent | 1255434882777053bca06656786abc1a598deda9 (diff) | |
Merge branch 'master' of github.com:TrinityCore/TrinityCore into 4.3.4
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; |
