Introduce "skip" in BLI_Iterator struct
authorDalai Felinto <dfelinto@gmail.com>
Mon, 30 Oct 2017 21:34:46 +0000 (19:34 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Mon, 30 Oct 2017 21:34:46 +0000 (19:34 -0200)
This helps iterators prevent recursion.

source/blender/blenlib/BLI_iterator.h

index a2ec21d89b3a96f2c5b86ca364c040b47f1589c0..39d5cc12d878786da0c422065d984047ef8ff173 100644 (file)
@@ -30,6 +30,7 @@
 typedef struct BLI_Iterator {
        void *current; /* current pointer we iterate over */
        void *data;    /* stored data required for this iterator */
+       bool skip;
        bool valid;
 } BLI_Iterator;
 
@@ -40,12 +41,18 @@ typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in);
 {                                                                                    \
        _type _instance;                                                                 \
        IteratorCb callback_end_func = callback_end;                                     \
-       BLI_Iterator iter_macro;                                                             \
+       BLI_Iterator iter_macro = {                                                      \
+               .skip = false,                                                               \
+       };                                                                               \
        for (callback_begin(&iter_macro, (_data_in));                                    \
             iter_macro.valid;                                                           \
             callback_next(&iter_macro))                                                 \
-    {                                                                                \
-           _instance = (_type ) iter_macro.current;
+       {                                                                                \
+               if (iter_macro.skip) {                                                       \
+                       iter_macro.skip = false;                                                 \
+                       continue;                                                                \
+               }                                                                            \
+               _instance = (_type ) iter_macro.current;
 
 #define ITER_END                                                                     \
        }                                                                                \