From 99782ea11be8f5a70d6ee06e0e5ee109c1537d48 Mon Sep 17 00:00:00 2001 From: Atdunbg <979541498@qq.com> Date: Wed, 18 Jun 2025 20:57:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8D=95=E6=B7=BB=E5=8A=A0UUID?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hazel/src/Hazel/Core/UUID.cpp | 25 ++++++++++++++++++++++ Hazel/src/Hazel/Core/UUID.h | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 Hazel/src/Hazel/Core/UUID.cpp create mode 100644 Hazel/src/Hazel/Core/UUID.h diff --git a/Hazel/src/Hazel/Core/UUID.cpp b/Hazel/src/Hazel/Core/UUID.cpp new file mode 100644 index 0000000..638b436 --- /dev/null +++ b/Hazel/src/Hazel/Core/UUID.cpp @@ -0,0 +1,25 @@ +// +// Created by sfd on 25-6-18. +// + +#include "UUID.h" + +#include + +namespace Hazel +{ + static std::random_device s_RandomDevice; + static std::mt19937_64 s_Engine(s_RandomDevice()); + static std::uniform_int_distribution s_UniformDistribution; + + UUID::UUID() + : m_UUID(s_UniformDistribution(s_Engine)) + { + + } + + UUID::UUID(const uint64_t uuid) + : m_UUID(uuid) + { + } +} diff --git a/Hazel/src/Hazel/Core/UUID.h b/Hazel/src/Hazel/Core/UUID.h new file mode 100644 index 0000000..eee0196 --- /dev/null +++ b/Hazel/src/Hazel/Core/UUID.h @@ -0,0 +1,40 @@ +// +// Created by sfd on 25-6-18. +// + +#ifndef UUID_H +#define UUID_H +#include +#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 + { + std::size_t operator() (const Hazel::UUID& uuid) const + { + return hash()((uint64_t)uuid); + } + }; + +} + + +#endif //UUID_H