forked from bartvdbraak/blender
BLI Listbase: Add iterator macro that increments an index
This commit is contained in:
parent
78d6c273b7
commit
ffa8e75799
@ -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
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user