/Users/deen/code/yugabyte-db/src/yb/util/strongly_typed_uuid.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_UTIL_STRONGLY_TYPED_UUID_H |
15 | | #define YB_UTIL_STRONGLY_TYPED_UUID_H |
16 | | |
17 | | #include <random> |
18 | | |
19 | | #include <boost/preprocessor/cat.hpp> |
20 | | |
21 | | #include "yb/gutil/endian.h" |
22 | | |
23 | | #include "yb/util/status_fwd.h" |
24 | | #include "yb/util/slice.h" |
25 | | #include "yb/util/uuid.h" |
26 | | |
27 | | // A "strongly-typed UUID" tool. This is needed to prevent passing the wrong UUID as a |
28 | | // function parameter, and to make callsites more readable by enforcing that MyUuidType is |
29 | | // specified instead of just UUID. Conversion from strongly-typed UUIDs |
30 | | // to regular UUIDs is automatic, but the reverse conversion is always explicit. |
31 | | #define YB_STRONGLY_TYPED_UUID(TypeName) \ |
32 | | struct BOOST_PP_CAT(TypeName, _Tag); \ |
33 | | typedef ::yb::StronglyTypedUuid<BOOST_PP_CAT(TypeName, _Tag)> TypeName; \ |
34 | | typedef boost::hash<TypeName> BOOST_PP_CAT(TypeName, Hash); \ |
35 | | Result<TypeName> BOOST_PP_CAT(FullyDecode, TypeName)(const Slice& slice); \ |
36 | | TypeName BOOST_PP_CAT(TryFullyDecode, TypeName)(const Slice& slice); \ |
37 | | Result<TypeName> BOOST_PP_CAT(Decode, TypeName)(Slice* slice); \ |
38 | | Result<TypeName> BOOST_PP_CAT(TypeName, FromString)(const std::string& strval); \ |
39 | | Result<TypeName> FromStringHelper(TypeName*, const std::string& strval); |
40 | | |
41 | | #define YB_STRONGLY_TYPED_UUID_IMPL(TypeName) \ |
42 | 18.1M | Result<TypeName> BOOST_PP_CAT(FullyDecode, TypeName)(const Slice& slice) { \ |
43 | 18.1M | return TypeName(VERIFY_RESULT(yb::Uuid::FullyDecode(slice, BOOST_PP_STRINGIZE(TypeName)))); \ |
44 | 18.1M | } \ Unexecuted instantiation: yb::FullyDecodeClientId(yb::Slice const&) yb::FullyDecodeTxnSnapshotId(yb::Slice const&) Line | Count | Source | 42 | 77 | Result<TypeName> BOOST_PP_CAT(FullyDecode, TypeName)(const Slice& slice) { \ | 43 | 77 | return TypeName(VERIFY_RESULT(yb::Uuid::FullyDecode(slice, BOOST_PP_STRINGIZE(TypeName)))); \ | 44 | 77 | } \ |
yb::FullyDecodeTxnSnapshotRestorationId(yb::Slice const&) Line | Count | Source | 42 | 67 | Result<TypeName> BOOST_PP_CAT(FullyDecode, TypeName)(const Slice& slice) { \ | 43 | 67 | return TypeName(VERIFY_RESULT(yb::Uuid::FullyDecode(slice, BOOST_PP_STRINGIZE(TypeName)))); \ | 44 | 67 | } \ |
yb::FullyDecodeSnapshotScheduleId(yb::Slice const&) Line | Count | Source | 42 | 543 | Result<TypeName> BOOST_PP_CAT(FullyDecode, TypeName)(const Slice& slice) { \ | 43 | 543 | return TypeName(VERIFY_RESULT(yb::Uuid::FullyDecode(slice, BOOST_PP_STRINGIZE(TypeName)))); \ | 44 | 543 | } \ |
yb::FullyDecodeTransactionId(yb::Slice const&) Line | Count | Source | 42 | 18.1M | Result<TypeName> BOOST_PP_CAT(FullyDecode, TypeName)(const Slice& slice) { \ | 43 | 18.1M | return TypeName(VERIFY_RESULT(yb::Uuid::FullyDecode(slice, BOOST_PP_STRINGIZE(TypeName)))); \ | 44 | 18.1M | } \ |
|
45 | 2.76k | TypeName BOOST_PP_CAT(TryFullyDecode, TypeName)(const Slice& slice) { \ |
46 | 2.76k | return TypeName(yb::Uuid::TryFullyDecode(slice)); \ |
47 | 2.76k | } \ Unexecuted instantiation: yb::TryFullyDecodeClientId(yb::Slice const&) yb::TryFullyDecodeTxnSnapshotId(yb::Slice const&) Line | Count | Source | 45 | 413 | TypeName BOOST_PP_CAT(TryFullyDecode, TypeName)(const Slice& slice) { \ | 46 | 413 | return TypeName(yb::Uuid::TryFullyDecode(slice)); \ | 47 | 413 | } \ |
yb::TryFullyDecodeTxnSnapshotRestorationId(yb::Slice const&) Line | Count | Source | 45 | 1.79k | TypeName BOOST_PP_CAT(TryFullyDecode, TypeName)(const Slice& slice) { \ | 46 | 1.79k | return TypeName(yb::Uuid::TryFullyDecode(slice)); \ | 47 | 1.79k | } \ |
yb::TryFullyDecodeSnapshotScheduleId(yb::Slice const&) Line | Count | Source | 45 | 552 | TypeName BOOST_PP_CAT(TryFullyDecode, TypeName)(const Slice& slice) { \ | 46 | 552 | return TypeName(yb::Uuid::TryFullyDecode(slice)); \ | 47 | 552 | } \ |
Unexecuted instantiation: yb::TryFullyDecodeTransactionId(yb::Slice const&) |
48 | 15.9M | Result<TypeName> BOOST_PP_CAT(Decode, TypeName)(Slice* slice) { \ |
49 | 15.9M | return TypeName(VERIFY_RESULT(yb::Uuid::Decode(slice))); \ |
50 | 15.9M | } \ Unexecuted instantiation: yb::DecodeClientId(yb::Slice*) Unexecuted instantiation: yb::DecodeTxnSnapshotId(yb::Slice*) Unexecuted instantiation: yb::DecodeTxnSnapshotRestorationId(yb::Slice*) Unexecuted instantiation: yb::DecodeSnapshotScheduleId(yb::Slice*) yb::DecodeTransactionId(yb::Slice*) Line | Count | Source | 48 | 15.9M | Result<TypeName> BOOST_PP_CAT(Decode, TypeName)(Slice* slice) { \ | 49 | 15.9M | return TypeName(VERIFY_RESULT(yb::Uuid::Decode(slice))); \ | 50 | 15.9M | } \ |
|
51 | 1.15k | Result<TypeName> BOOST_PP_CAT(TypeName, FromString)(const std::string& strval) { \ |
52 | 1.15k | return TypeName(VERIFY_RESULT(::yb::Uuid::FromString(strval))); \ |
53 | 1.15k | } \ Unexecuted instantiation: yb::ClientIdFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: yb::TxnSnapshotIdFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) yb::TxnSnapshotRestorationIdFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 51 | 5 | Result<TypeName> BOOST_PP_CAT(TypeName, FromString)(const std::string& strval) { \ | 52 | 5 | return TypeName(VERIFY_RESULT(::yb::Uuid::FromString(strval))); \ | 53 | 5 | } \ |
yb::SnapshotScheduleIdFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 51 | 10 | Result<TypeName> BOOST_PP_CAT(TypeName, FromString)(const std::string& strval) { \ | 52 | 10 | return TypeName(VERIFY_RESULT(::yb::Uuid::FromString(strval))); \ | 53 | 10 | } \ |
yb::TransactionIdFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 51 | 1.13k | Result<TypeName> BOOST_PP_CAT(TypeName, FromString)(const std::string& strval) { \ | 52 | 1.13k | return TypeName(VERIFY_RESULT(::yb::Uuid::FromString(strval))); \ | 53 | 1.13k | } \ |
|
54 | 1.15k | Result<TypeName> FromStringHelper(TypeName*, const std::string& strval) { \ |
55 | 1.15k | return BOOST_PP_CAT(TypeName, FromString)(strval); \ |
56 | 1.15k | } Unexecuted instantiation: yb::FromStringHelper(yb::StronglyTypedUuid<yb::ClientId_Tag>*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: yb::FromStringHelper(yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) yb::FromStringHelper(yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 54 | 5 | Result<TypeName> FromStringHelper(TypeName*, const std::string& strval) { \ | 55 | 5 | return BOOST_PP_CAT(TypeName, FromString)(strval); \ | 56 | 5 | } |
yb::FromStringHelper(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 54 | 10 | Result<TypeName> FromStringHelper(TypeName*, const std::string& strval) { \ | 55 | 10 | return BOOST_PP_CAT(TypeName, FromString)(strval); \ | 56 | 10 | } |
yb::FromStringHelper(yb::StronglyTypedUuid<yb::TransactionId_Tag>*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 54 | 1.13k | Result<TypeName> FromStringHelper(TypeName*, const std::string& strval) { \ | 55 | 1.13k | return BOOST_PP_CAT(TypeName, FromString)(strval); \ | 56 | 1.13k | } |
|
57 | | |
58 | | namespace yb { |
59 | | |
60 | | template <class Tag> |
61 | | class StronglyTypedUuid { |
62 | | public: |
63 | | // This is public so that we can construct a strongly-typed UUID value out of a regular one. |
64 | | // In that case we'll have to spell out the class name, which will enforce readability. |
65 | 139M | explicit StronglyTypedUuid(const Uuid& uuid) : uuid_(uuid) {} yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::StronglyTypedUuid(yb::Uuid const&) Line | Count | Source | 65 | 1.92k | explicit StronglyTypedUuid(const Uuid& uuid) : uuid_(uuid) {} |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::StronglyTypedUuid(yb::Uuid const&) Line | Count | Source | 65 | 1.19k | explicit StronglyTypedUuid(const Uuid& uuid) : uuid_(uuid) {} |
yb::StronglyTypedUuid<yb::TransactionId_Tag>::StronglyTypedUuid(yb::Uuid const&) Line | Count | Source | 65 | 133M | explicit StronglyTypedUuid(const Uuid& uuid) : uuid_(uuid) {} |
yb::StronglyTypedUuid<yb::ClientId_Tag>::StronglyTypedUuid(yb::Uuid const&) Line | Count | Source | 65 | 6.01M | explicit StronglyTypedUuid(const Uuid& uuid) : uuid_(uuid) {} |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::StronglyTypedUuid(yb::Uuid const&) Line | Count | Source | 65 | 667 | explicit StronglyTypedUuid(const Uuid& uuid) : uuid_(uuid) {} |
|
66 | | |
67 | 18.1M | StronglyTypedUuid<Tag>(uint64_t pb1, uint64_t pb2) { |
68 | 18.1M | pb1 = LittleEndian::FromHost64(pb1); |
69 | 18.1M | pb2 = LittleEndian::FromHost64(pb2); |
70 | 18.1M | memcpy(uuid_.data(), &pb1, sizeof(pb1)); |
71 | 18.1M | memcpy(uuid_.data() + sizeof(pb1), &pb2, sizeof(pb2)); |
72 | 18.1M | } yb::StronglyTypedUuid<yb::TransactionId_Tag>::StronglyTypedUuid(unsigned long long, unsigned long long) Line | Count | Source | 67 | 2.26k | StronglyTypedUuid<Tag>(uint64_t pb1, uint64_t pb2) { | 68 | 2.26k | pb1 = LittleEndian::FromHost64(pb1); | 69 | 2.26k | pb2 = LittleEndian::FromHost64(pb2); | 70 | 2.26k | memcpy(uuid_.data(), &pb1, sizeof(pb1)); | 71 | 2.26k | memcpy(uuid_.data() + sizeof(pb1), &pb2, sizeof(pb2)); | 72 | 2.26k | } |
yb::StronglyTypedUuid<yb::ClientId_Tag>::StronglyTypedUuid(unsigned long long, unsigned long long) Line | Count | Source | 67 | 18.1M | StronglyTypedUuid<Tag>(uint64_t pb1, uint64_t pb2) { | 68 | 18.1M | pb1 = LittleEndian::FromHost64(pb1); | 69 | 18.1M | pb2 = LittleEndian::FromHost64(pb2); | 70 | 18.1M | memcpy(uuid_.data(), &pb1, sizeof(pb1)); | 71 | 18.1M | memcpy(uuid_.data() + sizeof(pb1), &pb2, sizeof(pb2)); | 72 | 18.1M | } |
|
73 | | |
74 | | // Gets the underlying UUID, only if not undefined. |
75 | 140M | const boost::uuids::uuid& operator *() const { |
76 | 140M | return uuid_.impl(); |
77 | 140M | } yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::operator*() const Line | Count | Source | 75 | 7.29k | const boost::uuids::uuid& operator *() const { | 76 | 7.29k | return uuid_.impl(); | 77 | 7.29k | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::operator*() const Line | Count | Source | 75 | 143 | const boost::uuids::uuid& operator *() const { | 76 | 143 | return uuid_.impl(); | 77 | 143 | } |
yb::StronglyTypedUuid<yb::TransactionId_Tag>::operator*() const Line | Count | Source | 75 | 94.6M | const boost::uuids::uuid& operator *() const { | 76 | 94.6M | return uuid_.impl(); | 77 | 94.6M | } |
yb::StronglyTypedUuid<yb::ClientId_Tag>::operator*() const Line | Count | Source | 75 | 45.6M | const boost::uuids::uuid& operator *() const { | 76 | 45.6M | return uuid_.impl(); | 77 | 45.6M | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::operator*() const Line | Count | Source | 75 | 591 | const boost::uuids::uuid& operator *() const { | 76 | 591 | return uuid_.impl(); | 77 | 591 | } |
|
78 | | |
79 | | // Converts a UUID to a string, returns "<Undefined{ClassName}>" if UUID is undefined, where |
80 | | // {ClassName} is the name associated with the Tag class. |
81 | 4.00M | std::string ToString() const { |
82 | 4.00M | return uuid_.ToString(); |
83 | 4.00M | } yb::StronglyTypedUuid<yb::TransactionId_Tag>::ToString() const Line | Count | Source | 81 | 4.00M | std::string ToString() const { | 82 | 4.00M | return uuid_.ToString(); | 83 | 4.00M | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::ToString() const Line | Count | Source | 81 | 474 | std::string ToString() const { | 82 | 474 | return uuid_.ToString(); | 83 | 474 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::ToString() const Line | Count | Source | 81 | 176 | std::string ToString() const { | 82 | 176 | return uuid_.ToString(); | 83 | 176 | } |
Unexecuted instantiation: yb::StronglyTypedUuid<yb::ClientId_Tag>::ToString() const yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::ToString() const Line | Count | Source | 81 | 17 | std::string ToString() const { | 82 | 17 | return uuid_.ToString(); | 83 | 17 | } |
|
84 | | |
85 | | // Returns true iff the UUID is nil. |
86 | 39.9M | bool IsNil() const { |
87 | 39.9M | return uuid_.IsNil(); |
88 | 39.9M | } yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::IsNil() const Line | Count | Source | 86 | 543 | bool IsNil() const { | 87 | 543 | return uuid_.IsNil(); | 88 | 543 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::IsNil() const Line | Count | Source | 86 | 1.86k | bool IsNil() const { | 87 | 1.86k | return uuid_.IsNil(); | 88 | 1.86k | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::IsNil() const Line | Count | Source | 86 | 596 | bool IsNil() const { | 87 | 596 | return uuid_.IsNil(); | 88 | 596 | } |
yb::StronglyTypedUuid<yb::ClientId_Tag>::IsNil() const Line | Count | Source | 86 | 26.6M | bool IsNil() const { | 87 | 26.6M | return uuid_.IsNil(); | 88 | 26.6M | } |
yb::StronglyTypedUuid<yb::TransactionId_Tag>::IsNil() const Line | Count | Source | 86 | 13.3M | bool IsNil() const { | 87 | 13.3M | return uuid_.IsNil(); | 88 | 13.3M | } |
|
89 | | |
90 | 2.69k | explicit operator bool() const { |
91 | 2.69k | return !IsNil(); |
92 | 2.69k | } yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::operator bool() const Line | Count | Source | 90 | 478 | explicit operator bool() const { | 91 | 478 | return !IsNil(); | 92 | 478 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::operator bool() const Line | Count | Source | 90 | 1.85k | explicit operator bool() const { | 91 | 1.85k | return !IsNil(); | 92 | 1.85k | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::operator bool() const Line | Count | Source | 90 | 357 | explicit operator bool() const { | 91 | 357 | return !IsNil(); | 92 | 357 | } |
|
93 | | |
94 | 65 | bool operator!() const { |
95 | 65 | return IsNil(); |
96 | 65 | } yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::operator!() const Line | Count | Source | 94 | 8 | bool operator!() const { | 95 | 8 | return IsNil(); | 96 | 8 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::operator!() const Line | Count | Source | 94 | 6 | bool operator!() const { | 95 | 6 | return IsNil(); | 96 | 6 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::operator!() const Line | Count | Source | 94 | 51 | bool operator!() const { | 95 | 51 | return IsNil(); | 96 | 51 | } |
|
97 | | |
98 | | // Represent UUID as pair of uint64 for protobuf serialization. |
99 | | // This serialization is independent of the byte order on the machine. |
100 | | // For instance we could convert UUID to pair of uint64 on little endian machine, transfer them |
101 | | // to big endian machine and UUID created from them will be the same. |
102 | 2.54M | std::pair<uint64_t, uint64_t> ToUInt64Pair() const { |
103 | 2.54M | std::pair<uint64_t, uint64_t> result; |
104 | 2.54M | memcpy(&result.first, uuid_.data(), sizeof(result.first)); |
105 | 2.54M | memcpy(&result.second, uuid_.data() + sizeof(result.first), sizeof(result.second)); |
106 | 2.54M | return std::pair<uint64_t, uint64_t>( |
107 | 2.54M | LittleEndian::ToHost64(result.first), LittleEndian::ToHost64(result.second)); |
108 | 2.54M | } |
109 | | |
110 | | // Represents an invalid UUID. |
111 | 104M | static StronglyTypedUuid<Tag> Nil() { |
112 | 104M | return StronglyTypedUuid(Uuid::Nil()); |
113 | 104M | } yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::Nil() Line | Count | Source | 111 | 51 | static StronglyTypedUuid<Tag> Nil() { | 112 | 51 | return StronglyTypedUuid(Uuid::Nil()); | 113 | 51 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::Nil() Line | Count | Source | 111 | 49 | static StronglyTypedUuid<Tag> Nil() { | 112 | 49 | return StronglyTypedUuid(Uuid::Nil()); | 113 | 49 | } |
yb::StronglyTypedUuid<yb::TransactionId_Tag>::Nil() Line | Count | Source | 111 | 98.4M | static StronglyTypedUuid<Tag> Nil() { | 112 | 98.4M | return StronglyTypedUuid(Uuid::Nil()); | 113 | 98.4M | } |
yb::StronglyTypedUuid<yb::ClientId_Tag>::Nil() Line | Count | Source | 111 | 5.97M | static StronglyTypedUuid<Tag> Nil() { | 112 | 5.97M | return StronglyTypedUuid(Uuid::Nil()); | 113 | 5.97M | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::Nil() Line | Count | Source | 111 | 61 | static StronglyTypedUuid<Tag> Nil() { | 112 | 61 | return StronglyTypedUuid(Uuid::Nil()); | 113 | 61 | } |
|
114 | | |
115 | | // Converts a string to a StronglyTypedUuid, if such a conversion exists. |
116 | | // The empty string maps to undefined. |
117 | 1.14k | static Result<StronglyTypedUuid<Tag>> FromString(const std::string& strval) { |
118 | 1.14k | return FromStringHelper(static_cast<StronglyTypedUuid<Tag>*>(nullptr), strval); |
119 | 1.14k | } yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::FromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 117 | 5 | static Result<StronglyTypedUuid<Tag>> FromString(const std::string& strval) { | 118 | 5 | return FromStringHelper(static_cast<StronglyTypedUuid<Tag>*>(nullptr), strval); | 119 | 5 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::FromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 117 | 10 | static Result<StronglyTypedUuid<Tag>> FromString(const std::string& strval) { | 118 | 10 | return FromStringHelper(static_cast<StronglyTypedUuid<Tag>*>(nullptr), strval); | 119 | 10 | } |
yb::StronglyTypedUuid<yb::TransactionId_Tag>::FromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Line | Count | Source | 117 | 1.12k | static Result<StronglyTypedUuid<Tag>> FromString(const std::string& strval) { | 118 | 1.12k | return FromStringHelper(static_cast<StronglyTypedUuid<Tag>*>(nullptr), strval); | 119 | 1.12k | } |
|
120 | | |
121 | | // Generate a random StronglyTypedUuid. |
122 | 458k | static StronglyTypedUuid<Tag> GenerateRandom() { |
123 | 458k | return StronglyTypedUuid(Uuid::Generate()); |
124 | 458k | } yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::GenerateRandom() Line | Count | Source | 122 | 22 | static StronglyTypedUuid<Tag> GenerateRandom() { | 123 | 22 | return StronglyTypedUuid(Uuid::Generate()); | 124 | 22 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::GenerateRandom() Line | Count | Source | 122 | 4 | static StronglyTypedUuid<Tag> GenerateRandom() { | 123 | 4 | return StronglyTypedUuid(Uuid::Generate()); | 124 | 4 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::GenerateRandom() Line | Count | Source | 122 | 8 | static StronglyTypedUuid<Tag> GenerateRandom() { | 123 | 8 | return StronglyTypedUuid(Uuid::Generate()); | 124 | 8 | } |
yb::StronglyTypedUuid<yb::ClientId_Tag>::GenerateRandom() Line | Count | Source | 122 | 46.2k | static StronglyTypedUuid<Tag> GenerateRandom() { | 123 | 46.2k | return StronglyTypedUuid(Uuid::Generate()); | 124 | 46.2k | } |
yb::StronglyTypedUuid<yb::TransactionId_Tag>::GenerateRandom() Line | Count | Source | 122 | 411k | static StronglyTypedUuid<Tag> GenerateRandom() { | 123 | 411k | return StronglyTypedUuid(Uuid::Generate()); | 124 | 411k | } |
|
125 | | |
126 | | static StronglyTypedUuid<Tag> GenerateRandom(std::mt19937_64* rng) { |
127 | | return StronglyTypedUuid(Uuid::Generate(rng)); |
128 | | } |
129 | | |
130 | 1.71M | uint8_t* data() { |
131 | 1.71M | return uuid_.data(); |
132 | 1.71M | } yb::StronglyTypedUuid<yb::TransactionId_Tag>::data() Line | Count | Source | 130 | 1.71M | uint8_t* data() { | 131 | 1.71M | return uuid_.data(); | 132 | 1.71M | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::data() Line | Count | Source | 130 | 60 | uint8_t* data() { | 131 | 60 | return uuid_.data(); | 132 | 60 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::data() Line | Count | Source | 130 | 114 | uint8_t* data() { | 131 | 114 | return uuid_.data(); | 132 | 114 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::data() Line | Count | Source | 130 | 29 | uint8_t* data() { | 131 | 29 | return uuid_.data(); | 132 | 29 | } |
|
133 | | |
134 | 3.89M | const uint8_t* data() const { |
135 | 3.89M | return uuid_.data(); |
136 | 3.89M | } yb::StronglyTypedUuid<yb::TransactionId_Tag>::data() const Line | Count | Source | 134 | 3.89M | const uint8_t* data() const { | 135 | 3.89M | return uuid_.data(); | 136 | 3.89M | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::data() const Line | Count | Source | 134 | 830 | const uint8_t* data() const { | 135 | 830 | return uuid_.data(); | 136 | 830 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::data() const Line | Count | Source | 134 | 8 | const uint8_t* data() const { | 135 | 8 | return uuid_.data(); | 136 | 8 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::data() const Line | Count | Source | 134 | 46 | const uint8_t* data() const { | 135 | 46 | return uuid_.data(); | 136 | 46 | } |
|
137 | | |
138 | 5.60M | size_t size() const { |
139 | 5.60M | return uuid_.size(); |
140 | 5.60M | } yb::StronglyTypedUuid<yb::TransactionId_Tag>::size() const Line | Count | Source | 138 | 5.60M | size_t size() const { | 139 | 5.60M | return uuid_.size(); | 140 | 5.60M | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::size() const Line | Count | Source | 138 | 1.01k | size_t size() const { | 139 | 1.01k | return uuid_.size(); | 140 | 1.01k | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::size() const Line | Count | Source | 138 | 105 | size_t size() const { | 139 | 105 | return uuid_.size(); | 140 | 105 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::size() const Line | Count | Source | 138 | 68 | size_t size() const { | 139 | 68 | return uuid_.size(); | 140 | 68 | } |
|
141 | | |
142 | 303M | Slice AsSlice() const { |
143 | 303M | return Slice(uuid_.AsSlice()); |
144 | 303M | } yb::StronglyTypedUuid<yb::TransactionId_Tag>::AsSlice() const Line | Count | Source | 142 | 303M | Slice AsSlice() const { | 143 | 303M | return Slice(uuid_.AsSlice()); | 144 | 303M | } |
yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag>::AsSlice() const Line | Count | Source | 142 | 30 | Slice AsSlice() const { | 143 | 30 | return Slice(uuid_.AsSlice()); | 144 | 30 | } |
yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag>::AsSlice() const Line | Count | Source | 142 | 87 | Slice AsSlice() const { | 143 | 87 | return Slice(uuid_.AsSlice()); | 144 | 87 | } |
yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag>::AsSlice() const Line | Count | Source | 142 | 96 | Slice AsSlice() const { | 143 | 96 | return Slice(uuid_.AsSlice()); | 144 | 96 | } |
|
145 | | |
146 | 208M | static size_t StaticSize() { |
147 | 208M | return boost::uuids::uuid::static_size(); |
148 | 208M | } |
149 | | |
150 | 0 | static size_t StaticStringSize() { |
151 | 0 | return 36; |
152 | 0 | } |
153 | | |
154 | | private: |
155 | | // Represented as an optional UUID. |
156 | | Uuid uuid_; |
157 | | }; |
158 | | |
159 | | template <class Tag> |
160 | 64.5k | std::ostream& operator << (std::ostream& out, const StronglyTypedUuid<Tag>& uuid) { |
161 | 64.5k | return out << uuid.ToString(); |
162 | 64.5k | } std::__1::basic_ostream<char, std::__1::char_traits<char> >& yb::operator<<<yb::TransactionId_Tag>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&) Line | Count | Source | 160 | 64.5k | std::ostream& operator << (std::ostream& out, const StronglyTypedUuid<Tag>& uuid) { | 161 | 64.5k | return out << uuid.ToString(); | 162 | 64.5k | } |
Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& yb::operator<<<yb::ClientId_Tag>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, yb::StronglyTypedUuid<yb::ClientId_Tag> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& yb::operator<<<yb::TxnSnapshotId_Tag>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag> const&) Unexecuted instantiation: std::__1::basic_ostream<char, std::__1::char_traits<char> >& yb::operator<<<yb::SnapshotScheduleId_Tag>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&) std::__1::basic_ostream<char, std::__1::char_traits<char> >& yb::operator<<<yb::TxnSnapshotRestorationId_Tag>(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag> const&) Line | Count | Source | 160 | 6 | std::ostream& operator << (std::ostream& out, const StronglyTypedUuid<Tag>& uuid) { | 161 | 6 | return out << uuid.ToString(); | 162 | 6 | } |
|
163 | | |
164 | | template <class Tag> |
165 | 42.8M | bool operator == (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { |
166 | 42.8M | return *lhs == *rhs; |
167 | 42.8M | } bool yb::operator==<yb::SnapshotScheduleId_Tag>(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&, yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&) Line | Count | Source | 165 | 746 | bool operator == (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { | 166 | 746 | return *lhs == *rhs; | 167 | 746 | } |
bool yb::operator==<yb::TxnSnapshotRestorationId_Tag>(yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag> const&, yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag> const&) Line | Count | Source | 165 | 51 | bool operator == (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { | 166 | 51 | return *lhs == *rhs; | 167 | 51 | } |
bool yb::operator==<yb::TransactionId_Tag>(yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&) Line | Count | Source | 165 | 27.5M | bool operator == (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { | 166 | 27.5M | return *lhs == *rhs; | 167 | 27.5M | } |
bool yb::operator==<yb::ClientId_Tag>(yb::StronglyTypedUuid<yb::ClientId_Tag> const&, yb::StronglyTypedUuid<yb::ClientId_Tag> const&) Line | Count | Source | 165 | 15.3M | bool operator == (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { | 166 | 15.3M | return *lhs == *rhs; | 167 | 15.3M | } |
bool yb::operator==<yb::TxnSnapshotId_Tag>(yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag> const&, yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag> const&) Line | Count | Source | 165 | 195 | bool operator == (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { | 166 | 195 | return *lhs == *rhs; | 167 | 195 | } |
|
168 | | |
169 | | template <class Tag> |
170 | 15 | bool operator != (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { |
171 | 15 | return !(lhs == rhs); |
172 | 15 | } |
173 | | |
174 | | template <class Tag> |
175 | 2.14k | bool operator < (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { |
176 | 2.14k | return *lhs < *rhs; |
177 | 2.14k | } Unexecuted instantiation: bool yb::operator<<yb::TransactionId_Tag>(yb::StronglyTypedUuid<yb::TransactionId_Tag> const&, yb::StronglyTypedUuid<yb::TransactionId_Tag> const&) bool yb::operator<<yb::SnapshotScheduleId_Tag>(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&, yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&) Line | Count | Source | 175 | 2.14k | bool operator < (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { | 176 | 2.14k | return *lhs < *rhs; | 177 | 2.14k | } |
|
178 | | |
179 | | template <class Tag> |
180 | | bool operator > (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { |
181 | | return rhs < lhs; |
182 | | } |
183 | | |
184 | | template <class Tag> |
185 | | bool operator <= (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { |
186 | | return !(rhs < lhs); |
187 | | } |
188 | | |
189 | | template <class Tag> |
190 | 0 | bool operator >= (const StronglyTypedUuid<Tag>& lhs, const StronglyTypedUuid<Tag>& rhs) noexcept { |
191 | 0 | return !(lhs < rhs); |
192 | 0 | } |
193 | | |
194 | | template <class Tag> |
195 | 54.5M | std::size_t hash_value(const StronglyTypedUuid<Tag>& u) noexcept { |
196 | 54.5M | return hash_value(*u); |
197 | 54.5M | } unsigned long yb::hash_value<yb::SnapshotScheduleId_Tag>(yb::StronglyTypedUuid<yb::SnapshotScheduleId_Tag> const&) Line | Count | Source | 195 | 1.51k | std::size_t hash_value(const StronglyTypedUuid<Tag>& u) noexcept { | 196 | 1.51k | return hash_value(*u); | 197 | 1.51k | } |
unsigned long yb::hash_value<yb::TxnSnapshotRestorationId_Tag>(yb::StronglyTypedUuid<yb::TxnSnapshotRestorationId_Tag> const&) Line | Count | Source | 195 | 42 | std::size_t hash_value(const StronglyTypedUuid<Tag>& u) noexcept { | 196 | 42 | return hash_value(*u); | 197 | 42 | } |
unsigned long yb::hash_value<yb::TransactionId_Tag>(yb::StronglyTypedUuid<yb::TransactionId_Tag> const&) Line | Count | Source | 195 | 39.5M | std::size_t hash_value(const StronglyTypedUuid<Tag>& u) noexcept { | 196 | 39.5M | return hash_value(*u); | 197 | 39.5M | } |
unsigned long yb::hash_value<yb::ClientId_Tag>(yb::StronglyTypedUuid<yb::ClientId_Tag> const&) Line | Count | Source | 195 | 15.0M | std::size_t hash_value(const StronglyTypedUuid<Tag>& u) noexcept { | 196 | 15.0M | return hash_value(*u); | 197 | 15.0M | } |
unsigned long yb::hash_value<yb::TxnSnapshotId_Tag>(yb::StronglyTypedUuid<yb::TxnSnapshotId_Tag> const&) Line | Count | Source | 195 | 201 | std::size_t hash_value(const StronglyTypedUuid<Tag>& u) noexcept { | 196 | 201 | return hash_value(*u); | 197 | 201 | } |
|
198 | | |
199 | | } // namespace yb |
200 | | |
201 | | #endif // YB_UTIL_STRONGLY_TYPED_UUID_H |