uuid.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. constexpr explicit operator bool() const {
  16. return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1];
  17. }
  18. 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. constexpr bool operator!=(const UUID& rhs) const {
  23. return !operator==(rhs);
  24. }
  25. // TODO(ogniK): Properly generate uuids based on RFC-4122
  26. 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. std::string Format() const;
  32. std::string FormatSwitch() const;
  33. };
  34. static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
  35. } // namespace Common