Blender  V2.93
BLI_iterator.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef struct BLI_Iterator {
28  void *current; /* current pointer we iterate over */
29  void *data; /* stored data required for this iterator */
30  bool skip;
31  bool valid;
33 
34 typedef void (*IteratorCb)(BLI_Iterator *iter);
35 typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in);
36 
37 #define BLI_ITERATOR_INIT(iter) \
38  { \
39  (iter)->skip = false; \
40  (iter)->valid = true; \
41  } \
42  ((void)0)
43 
44 #define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance) \
45  { \
46  _type _instance; \
47  IteratorCb callback_end_func = callback_end; \
48  BLI_Iterator iter_macro; \
49  BLI_ITERATOR_INIT(&iter_macro); \
50  for (callback_begin(&iter_macro, (_data_in)); iter_macro.valid; callback_next(&iter_macro)) { \
51  if (iter_macro.skip) { \
52  iter_macro.skip = false; \
53  continue; \
54  } \
55  _instance = (_type)iter_macro.current;
56 
57 #define ITER_END \
58  } \
59  callback_end_func(&iter_macro); \
60  } \
61  ((void)0)
62 
63 #ifdef __cplusplus
64 }
65 #endif
void(* IteratorCb)(BLI_Iterator *iter)
Definition: BLI_iterator.h:34
struct BLI_Iterator BLI_Iterator
void(* IteratorBeginCb)(BLI_Iterator *iter, void *data_in)
Definition: BLI_iterator.h:35
void * current
Definition: BLI_iterator.h:28