uuid.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = INVALID_UUID;
  12. constexpr 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[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1];
  17. }
  18. [[nodiscard]] constexpr bool operator==(const UUID& rhs) const {
  19. // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20
  20. return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1];
  21. }
  22. [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const {
  23. return !operator==(rhs);
  24. }
  25. // TODO(ogniK): Properly generate uuids based on RFC-4122
  26. [[nodiscard]] static UUID Generate();
  27. // Set the UUID to {0,0} to be considered an invalid user
  28. constexpr void Invalidate() {
  29. uuid = INVALID_UUID;
  30. }
  31. // TODO(ogniK): Properly generate a Nintendo ID
  32. [[nodiscard]] constexpr u64 GetNintendoID() const {
  33. return uuid[0];
  34. }
  35. [[nodiscard]] std::string Format() const;
  36. [[nodiscard]] std::string FormatSwitch() const;
  37. };
  38. static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
  39. } // namespace Common