// Copyright (C) 2022 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 namespace Nz { inline Uuid::Uuid() { m_guid.fill(0); } inline Uuid::Uuid(const std::array guid) : m_guid(guid) { } inline bool Uuid::IsNull() const { Uuid NullGuid; return *this == NullGuid; } inline const std::array& Uuid::ToArray() const { return m_guid; } inline std::string Uuid::ToString() const { std::array guidStr = ToStringArray(); return std::string(guidStr.data(), guidStr.size() - 1); } bool operator==(const Uuid& lhs, const Uuid& rhs) { return lhs.ToArray() == rhs.ToArray(); } bool operator!=(const Uuid& lhs, const Uuid& rhs) { return lhs.ToArray() != rhs.ToArray(); } bool operator<(const Uuid& lhs, const Uuid& rhs) { return lhs.ToArray() < rhs.ToArray(); } bool operator<=(const Uuid& lhs, const Uuid& rhs) { return lhs.ToArray() <= rhs.ToArray(); } bool operator>(const Uuid& lhs, const Uuid& rhs) { return lhs.ToArray() > rhs.ToArray(); } bool operator>=(const Uuid& lhs, const Uuid& rhs) { return lhs.ToArray() >= rhs.ToArray(); } } namespace Nz { bool Serialize(SerializationContext& context, const Uuid& value, TypeTag) { const std::array& array = value.ToArray(); if (context.stream->Write(array.data(), array.size()) != array.size()) return false; return true; } bool Unserialize(SerializationContext& context, Uuid* value, TypeTag) { std::array array; if (context.stream->Read(array.data(), array.size()) != array.size()) return false; *value = Uuid(array); return true; } } namespace std { template <> struct hash { size_t operator()(const Nz::Uuid& guid) const { // DJB2 algorithm http://www.cse.yorku.ca/~oz/hash.html size_t h = 5381; const array& data = guid.ToArray(); for (size_t i = 0; i < data.size(); ++i) h = ((h << 5) + h) + data[i]; return h; } }; } #include