aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-10-02 16:51:30 +0200
committerSven Gothel <[email protected]>2021-10-02 16:51:30 +0200
commit06e24e01e7549ce14906e8642405e9468b8a9393 (patch)
treed969069859f47a5bc1f2e747f7fe25b48a8c0b26 /src
parent55e4e3cd9ffdf6ae4d73e72e79577b549e81b24b (diff)
uuid_t: Add uuid_t::equivalent(..) method fo relaxed comparison on different uuid_t; Add API doc to uuid_t::operator==(..) ..
The operator uuid_t::operator==(..) and uuid_t::operator!=(..) perform strict comparison and will fail on different uuid_t types (TypeSize). Adding convenient relaxed uuid_t::equivalent(..) method, allowing conversion to uuid128_t in case of different types before comparison. Tested with test_uuid.cpp
Diffstat (limited to 'src')
-rw-r--r--src/uuid.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/uuid.cpp b/src/uuid.cpp
index 879ba57..8bd954b 100644
--- a/src/uuid.cpp
+++ b/src/uuid.cpp
@@ -91,6 +91,16 @@ std::unique_ptr<uuid_t> uuid_t::clone() const noexcept {
abort(); // never reached
}
+bool uuid_t::equivalent(uuid_t const &o) const noexcept {
+ if( this == &o ) {
+ return true;
+ }
+ if( getTypeSize() == o.getTypeSize() ) {
+ return *this == o;
+ }
+ return toUUID128() == o.toUUID128();
+}
+
uuid128_t uuid_t::toUUID128(uuid128_t const & base_uuid, jau::nsize_t const uuid32_le_octet_index) const noexcept {
switch(type) {
case TypeSize::UUID16_SZ: return uuid128_t( *( static_cast<const uuid16_t*>(this) ), base_uuid, uuid32_le_octet_index);