mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
17402cc43f
This is the strict version, ID → Id, UI → Ui, except DDNet which stays DDNet. This would fix #7750. Done using a naive rename script (for bash, use `shopt -s globstar`): ```fish sed -i \ -e 's/\([a-z]_\?\)ID/\1Id/g' \ -e 's/\([^ ]\)\<UI\>/\1Ui/g' \ -e 's/UI()/Ui()/g' \ -e 's/\<CUI\>/CUi/g' \ -e 's/\([\ta-z.(&]\|[,=|] \)ID\>/\1Id/g' \ -e 's/\<ID\>\([^ ").]\)/Id\1/g' \ -e 's/\<ID\([0-9]\)/Id\1/g' \ -e 's/\<ID\>\( [<=>:+*/-]\)/Id\1/g' \ -e 's/int ID/int Id/g' \ -e 's/\([a-z]_\?\)GPU/\1Gpu/g' \ -e 's/\([a-z]_\?\)IP/\1Ip/g' \ -e 's/\([a-z]_\?\)CID/\1Cid/g' \ -e 's/\([a-z]_\?\)MySQL/\1Mysql/g' \ -e 's/MySql/Mysql/g' \ -e 's/\([a-xz]_\?\)SQL/\1Sql/g' \ -e 's/DPMode/DpMode/g' \ -e 's/TTWGraphics/TTwGraphics/g' \ \ -e 's/Ipointer/IPointer/g' \ -e 's/\.vendorId/.vendorID/g' \ -e 's/\.windowId/.windowID/g' \ -e 's/SDL_GetWindowFromId/SDL_GetWindowFromID/g' \ -e 's/SDL_AudioDeviceId/SDL_AudioDeviceID/g' \ -e 's/SDL_JoystickId/SDL_JoystickID/g' \ -e 's/SDL_JoystickInstanceId/SDL_JoystickInstanceID/g' \ -e 's/AVCodecId/AVCodecID/g' \ src/**/*.cpp src/**/*.h {datasrc,scripts}/**/*.py git checkout -- src/engine/external ``` I like this option because it presents clear rules. Still needs fixups because of the naive replacement, I'd do this if we want this merged.
74 lines
1.5 KiB
C++
74 lines
1.5 KiB
C++
#ifndef ENGINE_SHARED_UUID_MANAGER_H
|
|
#define ENGINE_SHARED_UUID_MANAGER_H
|
|
|
|
#include <vector>
|
|
|
|
enum
|
|
{
|
|
UUID_MAXSTRSIZE = 37, // 12345678-0123-5678-0123-567890123456
|
|
|
|
UUID_INVALID = -2,
|
|
UUID_UNKNOWN = -1,
|
|
|
|
OFFSET_UUID = 1 << 16,
|
|
};
|
|
|
|
struct CUuid
|
|
{
|
|
unsigned char m_aData[16];
|
|
|
|
bool operator==(const CUuid &Other) const;
|
|
bool operator!=(const CUuid &Other) const;
|
|
bool operator<(const CUuid &Other) const;
|
|
};
|
|
|
|
extern const CUuid UUID_ZEROED;
|
|
|
|
CUuid RandomUuid();
|
|
CUuid CalculateUuid(const char *pName);
|
|
// The buffer length should be at least UUID_MAXSTRSIZE.
|
|
void FormatUuid(CUuid Uuid, char *pBuffer, unsigned BufferLength);
|
|
// Returns nonzero on failure.
|
|
int ParseUuid(CUuid *pUuid, const char *pBuffer);
|
|
|
|
struct CName
|
|
{
|
|
CUuid m_Uuid;
|
|
const char *m_pName;
|
|
};
|
|
|
|
struct CNameIndexed
|
|
{
|
|
CUuid m_Uuid;
|
|
int m_Id;
|
|
|
|
bool operator<(const CNameIndexed &Other) const { return m_Uuid < Other.m_Uuid; }
|
|
bool operator==(const CNameIndexed &Other) const { return m_Uuid == Other.m_Uuid; }
|
|
};
|
|
|
|
class CPacker;
|
|
class CUnpacker;
|
|
|
|
class CUuidManager
|
|
{
|
|
std::vector<CName> m_vNames;
|
|
std::vector<CNameIndexed> m_vNamesSorted;
|
|
|
|
public:
|
|
void RegisterName(int Id, const char *pName);
|
|
CUuid GetUuid(int Id) const;
|
|
const char *GetName(int Id) const;
|
|
int LookupUuid(CUuid Uuid) const;
|
|
int NumUuids() const;
|
|
|
|
int UnpackUuid(CUnpacker *pUnpacker) const;
|
|
int UnpackUuid(CUnpacker *pUnpacker, CUuid *pOut) const;
|
|
void PackUuid(int Id, CPacker *pPacker) const;
|
|
|
|
void DebugDump() const;
|
|
};
|
|
|
|
extern CUuidManager g_UuidManager;
|
|
|
|
#endif // ENGINE_SHARED_UUID_MANAGER_H
|