简单添加UUID生成功能
This commit is contained in:
25
Hazel/src/Hazel/Core/UUID.cpp
Normal file
25
Hazel/src/Hazel/Core/UUID.cpp
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
40
Hazel/src/Hazel/Core/UUID.h
Normal file
40
Hazel/src/Hazel/Core/UUID.h
Normal 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
|
||||
Reference in New Issue
Block a user