Blender V5.0
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
10
11#include <stdbool.h>
12
13typedef struct BLI_Iterator {
14 void *current; /* current pointer we iterate over */
15 void *data; /* stored data required for this iterator */
16 bool skip;
17 bool valid;
19
20typedef void (*IteratorCb)(BLI_Iterator *iter);
21typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in);
22
23#define BLI_ITERATOR_INIT(iter) \
24 { \
25 (iter)->skip = false; \
26 (iter)->valid = true; \
27 } \
28 ((void)0)
29
30#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance) \
31 { \
32 _type _instance; \
33 IteratorCb callback_end_func = callback_end; \
34 BLI_Iterator iter_macro; \
35 BLI_ITERATOR_INIT(&iter_macro); \
36 for (callback_begin(&iter_macro, (_data_in)); iter_macro.valid; callback_next(&iter_macro)) { \
37 if (iter_macro.skip) { \
38 iter_macro.skip = false; \
39 continue; \
40 } \
41 _instance = (_type)iter_macro.current;
42
43#define ITER_END \
44 } \
45 callback_end_func(&iter_macro); \
46 } \
47 ((void)0)
void(* IteratorCb)(BLI_Iterator *iter)
void(* IteratorBeginCb)(BLI_Iterator *iter, void *data_in)