2017-05-21 23:07:13 +00:00
|
|
|
#ifndef ENGINE_SHARED_UUID_MANAGER_H
|
|
|
|
#define ENGINE_SHARED_UUID_MANAGER_H
|
|
|
|
|
2022-05-23 20:01:12 +00:00
|
|
|
#include <vector>
|
2017-05-21 23:07:13 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
UUID_MAXSTRSIZE = 37, // 12345678-0123-5678-0123-567890123456
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
UUID_INVALID = -2,
|
|
|
|
UUID_UNKNOWN = -1,
|
2017-05-21 23:07:13 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
OFFSET_UUID = 1 << 16,
|
2017-05-21 23:07:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CUuid
|
|
|
|
{
|
|
|
|
unsigned char m_aData[16];
|
|
|
|
|
2020-10-10 09:51:06 +00:00
|
|
|
bool operator==(const CUuid &Other) const;
|
|
|
|
bool operator!=(const CUuid &Other) const;
|
2023-12-11 14:40:09 +00:00
|
|
|
bool operator<(const CUuid &Other) const;
|
2017-05-21 23:07:13 +00:00
|
|
|
};
|
|
|
|
|
2023-11-27 21:29:14 +00:00
|
|
|
extern const CUuid UUID_ZEROED;
|
|
|
|
|
2017-09-12 12:58:44 +00:00
|
|
|
CUuid RandomUuid();
|
2017-05-21 23:07:13 +00:00
|
|
|
CUuid CalculateUuid(const char *pName);
|
2020-05-20 19:21:40 +00:00
|
|
|
// The buffer length should be at least UUID_MAXSTRSIZE.
|
2017-05-21 23:07:13 +00:00
|
|
|
void FormatUuid(CUuid Uuid, char *pBuffer, unsigned BufferLength);
|
2021-01-22 20:04:18 +00:00
|
|
|
// Returns nonzero on failure.
|
|
|
|
int ParseUuid(CUuid *pUuid, const char *pBuffer);
|
2017-05-21 23:07:13 +00:00
|
|
|
|
|
|
|
struct CName
|
|
|
|
{
|
|
|
|
CUuid m_Uuid;
|
|
|
|
const char *m_pName;
|
|
|
|
};
|
|
|
|
|
2020-10-10 09:51:06 +00:00
|
|
|
struct CNameIndexed
|
|
|
|
{
|
|
|
|
CUuid m_Uuid;
|
2024-03-05 14:44:09 +00:00
|
|
|
int m_Id;
|
2020-10-10 09:51:06 +00:00
|
|
|
|
|
|
|
bool operator<(const CNameIndexed &Other) const { return m_Uuid < Other.m_Uuid; }
|
2022-05-23 20:01:12 +00:00
|
|
|
bool operator==(const CNameIndexed &Other) const { return m_Uuid == Other.m_Uuid; }
|
2020-10-10 09:51:06 +00:00
|
|
|
};
|
|
|
|
|
2017-05-21 23:07:13 +00:00
|
|
|
class CPacker;
|
|
|
|
class CUnpacker;
|
|
|
|
|
|
|
|
class CUuidManager
|
|
|
|
{
|
2022-05-23 20:49:06 +00:00
|
|
|
std::vector<CName> m_vNames;
|
|
|
|
std::vector<CNameIndexed> m_vNamesSorted;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2017-05-21 23:07:13 +00:00
|
|
|
public:
|
2024-03-05 14:44:09 +00:00
|
|
|
void RegisterName(int Id, const char *pName);
|
|
|
|
CUuid GetUuid(int Id) const;
|
|
|
|
const char *GetName(int Id) const;
|
2017-05-21 23:07:13 +00:00
|
|
|
int LookupUuid(CUuid Uuid) const;
|
2017-11-18 02:08:16 +00:00
|
|
|
int NumUuids() const;
|
2017-05-21 23:07:13 +00:00
|
|
|
|
|
|
|
int UnpackUuid(CUnpacker *pUnpacker) const;
|
|
|
|
int UnpackUuid(CUnpacker *pUnpacker, CUuid *pOut) const;
|
2024-03-05 14:44:09 +00:00
|
|
|
void PackUuid(int Id, CPacker *pPacker) const;
|
2017-05-21 23:07:13 +00:00
|
|
|
|
|
|
|
void DebugDump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern CUuidManager g_UuidManager;
|
|
|
|
|
|
|
|
#endif // ENGINE_SHARED_UUID_MANAGER_H
|