uuid_generic.ipp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef BOOST_UUID_DETAIL_UUID_GENERIC_IPP_INCLUDED
  2. #define BOOST_UUID_DETAIL_UUID_GENERIC_IPP_INCLUDED
  3. // Copyright 2024 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/uuid/detail/endian.hpp>
  7. #include <cstdint>
  8. #if defined(BOOST_UUID_REPORT_IMPLEMENTATION)
  9. #include <boost/config/pragma_message.hpp>
  10. BOOST_PRAGMA_MESSAGE( "Using uuid_generic.ipp" )
  11. #endif
  12. namespace boost {
  13. namespace uuids {
  14. inline bool uuid::is_nil() const noexcept
  15. {
  16. std::uint64_t v = detail::load_native_u64( this->data + 0 );
  17. std::uint64_t w = detail::load_native_u64( this->data + 8 );
  18. return v == 0 && w == 0;
  19. }
  20. inline void uuid::swap( uuid& rhs ) noexcept
  21. {
  22. std::uint64_t v1 = detail::load_native_u64( this->data + 0 );
  23. std::uint64_t w1 = detail::load_native_u64( this->data + 8 );
  24. std::uint64_t v2 = detail::load_native_u64( rhs.data + 0 );
  25. std::uint64_t w2 = detail::load_native_u64( rhs.data + 8 );
  26. detail::store_native_u64( this->data + 0, v2 );
  27. detail::store_native_u64( this->data + 8, w2 );
  28. detail::store_native_u64( rhs.data + 0, v1 );
  29. detail::store_native_u64( rhs.data + 8, w1 );
  30. }
  31. inline bool operator==( uuid const& lhs, uuid const& rhs ) noexcept
  32. {
  33. std::uint64_t v1 = detail::load_native_u64( lhs.data + 0 );
  34. std::uint64_t w1 = detail::load_native_u64( lhs.data + 8 );
  35. std::uint64_t v2 = detail::load_native_u64( rhs.data + 0 );
  36. std::uint64_t w2 = detail::load_native_u64( rhs.data + 8 );
  37. return v1 == v2 && w1 == w2;
  38. }
  39. inline bool operator<( uuid const& lhs, uuid const& rhs ) noexcept
  40. {
  41. std::uint64_t v1 = detail::load_big_u64( lhs.data + 0 );
  42. std::uint64_t w1 = detail::load_big_u64( lhs.data + 8 );
  43. std::uint64_t v2 = detail::load_big_u64( rhs.data + 0 );
  44. std::uint64_t w2 = detail::load_big_u64( rhs.data + 8 );
  45. return v1 < v2 || ( !( v2 < v1 ) && w1 < w2 );
  46. }
  47. #if defined(BOOST_UUID_HAS_THREE_WAY_COMPARISON)
  48. inline std::strong_ordering operator<=> (uuid const& lhs, uuid const& rhs) noexcept
  49. {
  50. std::uint64_t v1 = detail::load_big_u64( lhs.data + 0 );
  51. std::uint64_t w1 = detail::load_big_u64( lhs.data + 8 );
  52. std::uint64_t v2 = detail::load_big_u64( rhs.data + 0 );
  53. std::uint64_t w2 = detail::load_big_u64( rhs.data + 8 );
  54. if( v1 < v2 ) return std::strong_ordering::less;
  55. if( v1 > v2 ) return std::strong_ordering::greater;
  56. return w1 <=> w2;
  57. }
  58. #endif
  59. } // namespace uuids
  60. } // namespace boost
  61. #endif // BOOST_UUID_DETAIL_UUID_GENERIC_IPP_INCLUDED