BLI Listbase: Add iterator macro that increments an index

This commit is contained in:
Hans Goudey 2020-08-18 21:38:18 -04:00
parent 78d6c273b7
commit ffa8e75799
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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))