[9571] Create and use ObjectGuidGenerator/IdGenerator template classes.

* This is let finally hide guid structure in ObjectGuid.h/.cpp code.
* Shared related code.

NOTE: while switch to use new clasess one more problem has been detected
with not-safe code in .pdump work for future per-map multi-threading.
It's need rewrited before will possible safe use in like case.
For current single world thread case it's safe.
This commit is contained in:
VladimirMangos 2010-03-11 15:50:45 +03:00
parent 873b2cab99
commit c4f3578226
8 changed files with 206 additions and 234 deletions

View file

@ -136,6 +136,8 @@ class ObjectGuid
// Possible removed in future for more strict control type conversions
void operator= (uint64 const& guid) { m_guid = guid; }
PackedGuid WriteAsPacked() const;
public: // accessors
uint64 const& GetRawValue() const { return m_guid; }
HighGuid GetHigh() const { return HighGuid((m_guid >> 48) & 0x0000FFFF); }
@ -147,6 +149,15 @@ class ObjectGuid
: uint32(m_guid & UI64LIT(0x00000000FFFFFFFF));
}
static uint32 GetMaxCounter(HighGuid high)
{
return HasEntry(high)
? uint32(0x00FFFFFF)
: uint32(0xFFFFFFFF);
}
uint32 GetMaxCounter() const { return GetMaxCounter(GetHigh()); }
bool IsEmpty() const { return m_guid == 0; }
bool IsCreature() const { return GetHigh() == HIGHGUID_UNIT; }
bool IsPet() const { return GetHigh() == HIGHGUID_PET; }
@ -161,9 +172,9 @@ class ObjectGuid
bool IsTransport() const { return GetHigh() == HIGHGUID_TRANSPORT; }
bool IsMOTransport() const { return GetHigh() == HIGHGUID_MO_TRANSPORT; }
TypeID GetTypeId()
static TypeID GetTypeId(HighGuid high)
{
switch(GetHigh())
switch(high)
{
case HIGHGUID_ITEM: return TYPEID_ITEM;
//case HIGHGUID_CONTAINER: return TYPEID_CONTAINER; HIGHGUID_CONTAINER==HIGHGUID_ITEM currently
@ -180,14 +191,17 @@ class ObjectGuid
}
}
PackedGuid WriteAsPacked() const;
TypeID GetTypeId() const { return GetTypeId(GetHigh()); }
public: // accessors - for debug
char const* GetTypeName() const;
static char const* GetTypeName(HighGuid high);
char const* GetTypeName() const { return !IsEmpty() ? GetTypeName(GetHigh()) : "None"; }
std::string GetString() const;
private: // internal functions
bool HasEntry() const
static bool HasEntry(HighGuid high)
{
switch(GetHigh())
switch(high)
{
case HIGHGUID_ITEM:
case HIGHGUID_PLAYER:
@ -205,6 +219,8 @@ class ObjectGuid
}
}
bool HasEntry() const { return HasEntry(GetHigh()); }
private: // fields
uint64 m_guid;
};
@ -229,6 +245,23 @@ class PackedGuid
ByteBuffer m_packedGuid;
};
template<HighGuid high>
class ObjectGuidGenerator
{
public: // constructors
explicit ObjectGuidGenerator(uint32 start = 1) : m_nextGuid(start) {}
public: // modifiers
void Set(uint32 val) { m_nextGuid = val; }
uint32 Generate();
public: // accessors
uint32 GetNextAfterMaxUsed() const { return m_nextGuid; }
private: // fields
uint32 m_nextGuid;
};
ByteBuffer& operator<< (ByteBuffer& buf, ObjectGuid const& guid);
ByteBuffer& operator>> (ByteBuffer& buf, ObjectGuid& guid);