Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-09-24 13:55:26 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-09-24 15:42:48 +0300
commitab9644382d14eb1254ce33e38227c874fd80a08f (patch)
tree935086c54a7b60d0597fb99330ec292ff118d8eb /source/blender/blenlib/intern/uuid.cc
parent2b9ca0f112ad41e9402d272cc0c691bd5e1c5956 (diff)
UUID: add less-than operator
Add `operator<` to C++ class to allow lexicographic ordering of UUIDs. This will be necessary when writing asset catalogs to disk in a predictable (i.e. ordered) manner.
Diffstat (limited to 'source/blender/blenlib/intern/uuid.cc')
-rw-r--r--source/blender/blenlib/intern/uuid.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc
index fe237b8aae6..3c86238036c 100644
--- a/source/blender/blenlib/intern/uuid.cc
+++ b/source/blender/blenlib/intern/uuid.cc
@@ -27,6 +27,7 @@
#include <random>
#include <sstream>
#include <string>
+#include <tuple>
/* Ensure the UUID struct doesn't have any padding, to be compatible with memcmp(). */
static_assert(sizeof(bUUID) == 16, "expect UUIDs to be 128 bit exactly");
@@ -189,4 +190,22 @@ bool operator!=(const bUUID uuid1, const bUUID uuid2)
return !(uuid1 == uuid2);
}
+bool operator<(const bUUID uuid1, const bUUID uuid2)
+{
+ auto simple_fields1 = std::tie(uuid1.time_low,
+ uuid1.time_mid,
+ uuid1.time_hi_and_version,
+ uuid1.clock_seq_hi_and_reserved,
+ uuid1.clock_seq_low);
+ auto simple_fields2 = std::tie(uuid2.time_low,
+ uuid2.time_mid,
+ uuid2.time_hi_and_version,
+ uuid2.clock_seq_hi_and_reserved,
+ uuid2.clock_seq_low);
+ if (simple_fields1 == simple_fields2) {
+ return std::memcmp(uuid1.node, uuid2.node, sizeof(uuid1.node)) < 0;
+ }
+ return simple_fields1 < simple_fields2;
+}
+
} // namespace blender