uuid.h 1.1 KB

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