19 #ifndef PSTORE_CORE_UUID_HPP 20 #define PSTORE_CORE_UUID_HPP 29 # define WIN32_LEAN_AND_MEAN 31 #elif defined(__APPLE__) 32 # include <uuid/uuid.h> 41 friend bool operator== (
uuid const & lhs,
uuid const & rhs) noexcept;
42 friend bool operator!= (
uuid const & lhs,
uuid const & rhs) noexcept;
43 friend bool operator< (
uuid const & lhs,
uuid const & rhs) noexcept;
44 friend bool operator<= (
uuid const & lhs,
uuid const & rhs) noexcept;
45 friend bool operator> (
uuid const & lhs,
uuid const & rhs) noexcept;
46 friend bool operator>= (
uuid const & lhs,
uuid const & rhs) noexcept;
49 static constexpr
auto elements = std::size_t{16};
55 using container_type = std::array<std::uint8_t, elements>;
56 using value_type = container_type::value_type;
57 using size_type = container_type::size_type;
58 using difference_type = container_type::difference_type;
60 using reference = container_type::reference;
61 using const_reference = container_type::const_reference;
62 using iterator = container_type::iterator;
63 using const_iterator = container_type::const_iterator;
68 explicit uuid (std::string
const & s);
71 explicit constexpr
uuid (container_type
const & c)
75 explicit uuid (UUID
const & u);
77 #elif defined(__APPLE__) 78 explicit uuid (uuid_t
const & bytes);
89 iterator begin () noexcept {
return std::begin (data_); }
90 const_iterator begin ()
const noexcept {
return std::begin (data_); }
91 iterator end () noexcept {
return std::end (data_); }
92 const_iterator end ()
const noexcept {
return std::end (data_); }
94 container_type
const & array ()
const noexcept {
return data_; }
96 enum class variant_type {
102 enum class version_type {
106 random_number_based = 4,
111 auto variant ()
const noexcept -> variant_type;
112 auto version ()
const noexcept -> version_type;
113 bool is_null ()
const noexcept;
116 std::string
str ()
const;
119 container_type data_{};
129 template <
typename Ty>
130 static std::uint8_t get_byte (Ty
const t,
unsigned const num) noexcept {
131 PSTORE_ASSERT (num <
sizeof (Ty));
132 return static_cast<std::uint8_t
> ((t >> (num * 8)) & 0xff);
136 PSTORE_STATIC_ASSERT (std::is_standard_layout<uuid>::value);
137 PSTORE_STATIC_ASSERT (
sizeof (
uuid) == 16);
139 std::ostream & operator<< (std::ostream & os, uuid::version_type v);
140 std::ostream & operator<< (std::ostream & os, uuid::variant_type v);
141 std::ostream & operator<< (std::ostream & os,
uuid const & m);
143 inline bool operator== (
uuid const & lhs,
uuid const & rhs) noexcept {
144 return lhs.data_ == rhs.data_;
146 inline bool operator< (
uuid const & lhs,
uuid const & rhs) noexcept {
147 return lhs.data_ < rhs.data_;
149 inline bool operator!= (
uuid const & lhs,
uuid const & rhs) noexcept {
150 return lhs.data_ != rhs.data_;
152 inline bool operator> (
uuid const & lhs,
uuid const & rhs) noexcept {
153 return lhs.data_ > rhs.data_;
155 inline bool operator<= (
uuid const & lhs,
uuid const & rhs) noexcept {
156 return lhs.data_ <= rhs.data_;
158 inline bool operator>= (
uuid const & lhs,
uuid const & rhs) noexcept {
159 return lhs.data_ >= rhs.data_;
164 #endif // PSTORE_CORE_UUID_HPP static constexpr auto string_length
RFC4122 defines the UUID string representation which includes 16 two-digit hex numbers and 4 hyphens...
Definition: uuid.hpp:53
constexpr uuid(container_type const &c)
A constructor used to construct a specific UUID from its binary value.
Definition: uuid.hpp:71
An implementation of the Haskell Maybe type.
auto variant() const noexcept -> variant_type
Definition: uuid.cpp:172
Definition: nonpod2.cpp:40
The uuid class is used to represent Universally Unique Identifiers (UUID) as defined by RFC 4122...
Definition: uuid.hpp:40
static maybe< uuid > from_string(std::string const &s)
Converts a string to a UUID following the convention defined by RFC4122.
Definition: uuid.cpp:134
std::string str() const
Yields a string representation of the UUID following the convention defined by RFC4122.
Definition: uuid.cpp:213