Blender V4.3
BLI_iterator.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15typedef struct BLI_Iterator {
16 void *current; /* current pointer we iterate over */
17 void *data; /* stored data required for this iterator */
18 bool skip;
19 bool valid;
21
22typedef void (*IteratorCb)(BLI_Iterator *iter);
23typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in);
24
25#define BLI_ITERATOR_INIT(iter) \
26 { \
27 (iter)->skip = false; \
28 (iter)->valid = true; \
29 } \
30 ((void)0)
31
32#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance) \
33 { \
34 _type _instance; \
35 IteratorCb callback_end_func = callback_end; \
36 BLI_Iterator iter_macro; \
37 BLI_ITERATOR_INIT(&iter_macro); \
38 for (callback_begin(&iter_macro, (_data_in)); iter_macro.valid; callback_next(&iter_macro)) { \
39 if (iter_macro.skip) { \
40 iter_macro.skip = false; \
41 continue; \
42 } \
43 _instance = (_type)iter_macro.current;
44
45#define ITER_END \
46 } \
47 callback_end_func(&iter_macro); \
48 } \
49 ((void)0)
50
51#ifdef __cplusplus
52}
53#endif
void(* IteratorCb)(BLI_Iterator *iter)
struct BLI_Iterator BLI_Iterator
void(* IteratorBeginCb)(BLI_Iterator *iter, void *data_in)