简单添加UUID生成功能

This commit is contained in:
2025-06-18 20:57:50 +08:00
parent 1f9b53609e
commit 99782ea11b
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,25 @@
//
// Created by sfd on 25-6-18.
//
#include "UUID.h"
#include <random>
namespace Hazel
{
static std::random_device s_RandomDevice;
static std::mt19937_64 s_Engine(s_RandomDevice());
static std::uniform_int_distribution<uint64_t> s_UniformDistribution;
UUID::UUID()
: m_UUID(s_UniformDistribution(s_Engine))
{
}
UUID::UUID(const uint64_t uuid)
: m_UUID(uuid)
{
}
}

View File

@ -0,0 +1,40 @@
//
// Created by sfd on 25-6-18.
//
#ifndef UUID_H
#define UUID_H
#include <xhash>
#include "Core.h"
namespace Hazel
{
class HAZEL_API UUID
{
public:
UUID();
UUID(uint64_t uuid);
UUID(const UUID&) = default;
operator uint64_t() const { return m_UUID;}
private:
uint64_t m_UUID;
};
}
namespace std
{
template<>
struct hash<Hazel::UUID>
{
std::size_t operator() (const Hazel::UUID& uuid) const
{
return hash<uint64_t>()((uint64_t)uuid);
}
};
}
#endif //UUID_H