// Copyright (C) 2024 Full Cycle Games // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #ifdef NAZARA_PLATFORM_WINDOWS #include #elif defined(NAZARA_PLATFORM_LINUX) || defined(NAZARA_PLATFORM_MACOS) || defined(NAZARA_PLATFORM_WEB) #include #endif #include namespace Nz { std::array Uuid::ToStringArray() const { std::array uuidStr; //< Including \0 std::snprintf(uuidStr.data(), uuidStr.size(), "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", m_uuid[0], m_uuid[1], m_uuid[2], m_uuid[3], m_uuid[4], m_uuid[5], m_uuid[6], m_uuid[7], m_uuid[8], m_uuid[9], m_uuid[10], m_uuid[11], m_uuid[12], m_uuid[13], m_uuid[14], m_uuid[15]); return uuidStr; } Uuid Uuid::Generate() { std::array uuid; #ifdef NAZARA_PLATFORM_WINDOWS GUID id; CoCreateGuid(&id); for (unsigned int i = 0; i < 4; ++i) uuid[i] = static_cast(id.Data1 >> ((3 - i) * 8 & 0xFF)); for (unsigned int i = 0; i < 2; ++i) uuid[4 + i] = static_cast(id.Data2 >> ((1 - i) * 8 & 0xFF)); for (unsigned int i = 0; i < 2; ++i) uuid[6 + i] = static_cast(id.Data3 >> ((1 - i) * 8 & 0xFF)); for (unsigned int i = 0; i < 8; ++i) uuid[8 + i] = static_cast(id.Data4[i]); #elif defined(NAZARA_PLATFORM_LINUX) || defined(NAZARA_PLATFORM_MACOS) || defined(NAZARA_PLATFORM_WEB) uuid_t id; uuid_generate(id); std::copy(std::begin(id), std::end(id), uuid.begin()); #else #error Missing platform support #endif return uuid; } }