uuid.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include "common/common_types.h"
  7. namespace Common {
  8. constexpr u128 INVALID_UUID{{0, 0}};
  9. struct UUID {
  10. // UUIDs which are 0 are considered invalid!
  11. u128 uuid;
  12. UUID() = default;
  13. constexpr explicit UUID(const u128& id) : uuid{id} {}
  14. constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {}
  15. [[nodiscard]] constexpr explicit operator bool() const {
  16. return uuid != INVALID_UUID;
  17. }
  18. [[nodiscard]] constexpr bool operator==(const UUID& rhs) const {
  19. return uuid == rhs.uuid;
  20. }
  21. [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const {
  22. return !operator==(rhs);
  23. }
  24. // TODO(ogniK): Properly generate uuids based on RFC-4122
  25. [[nodiscard]] static UUID Generate();
  26. // Set the UUID to {0,0} to be considered an invalid user
  27. constexpr void Invalidate() {
  28. uuid = INVALID_UUID;
  29. }
  30. // TODO(ogniK): Properly generate a Nintendo ID
  31. [[nodiscard]] constexpr u64 GetNintendoID() const {
  32. return uuid[0];
  33. }
  34. [[nodiscard]] std::string Format() const;
  35. [[nodiscard]] std::string FormatSwitch() const;
  36. };
  37. static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
  38. } // namespace Common