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:
authorHans Goudey <h.goudey@me.com>2020-08-19 04:38:18 +0300
committerHans Goudey <h.goudey@me.com>2020-08-19 04:38:18 +0300
commitffa8e7579916609b4ddd4dda031cf2a3a7eaefb1 (patch)
treebb883bb0b5c6915f79e1da692b976b1f30f4cc31
parent78d6c273b75363e9ecc28a92ecc8b320e4baad1d (diff)
BLI Listbase: Add iterator macro that increments an index
-rw-r--r--.clang-format1
-rw-r--r--source/blender/blenlib/BLI_listbase.h9
2 files changed, 10 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
index cb5cdab496f..4db1b664fdb 100644
--- a/.clang-format
+++ b/.clang-format
@@ -238,6 +238,7 @@ ForEachMacros:
- LISTBASE_FOREACH_BACKWARD
- LISTBASE_FOREACH_MUTABLE
- LISTBASE_FOREACH_BACKWARD_MUTABLE
+ - LISTBASE_FOREACH_INDEX
- MAN_ITER_AXES_BEGIN
- NODE_INSTANCE_HASH_ITER
- NODE_SOCKET_TYPES_BEGIN
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index fa7cf7a1847..aff80a2bd86 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -171,6 +171,15 @@ struct LinkData *BLI_genericNodeN(void *data);
#define LISTBASE_FOREACH(type, var, list) \
for (type var = (type)((list)->first); var != NULL; var = (type)(((Link *)(var))->next))
+/**
+ * A version of #LISTBASE_FOREACH that supports incrementing an index variable at every step.
+ * Including this in the macro helps prevent mistakes where "continue" mistakenly skips the
+ * incrementation.
+ */
+#define LISTBASE_FOREACH_INDEX(type, var, list, index_var) \
+ for (type var = (((void)(index_var = 0)), (type)((list)->first)); var != NULL; \
+ var = (type)(((Link *)(var))->next), index_var++)
+
#define LISTBASE_FOREACH_BACKWARD(type, var, list) \
for (type var = (type)((list)->last); var != NULL; var = (type)(((Link *)(var))->prev))