doxygen: add newline after \file
[blender.git] / source / blender / blenlib / BLI_iterator.h
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 #ifndef __BLI_ITERATOR_H__
18 #define __BLI_ITERATOR_H__
19
20 /** \file
21  * \ingroup bli
22  */
23
24 typedef struct BLI_Iterator {
25         void *current; /* current pointer we iterate over */
26         void *data;    /* stored data required for this iterator */
27         bool skip;
28         bool valid;
29 } BLI_Iterator;
30
31 typedef void (*IteratorCb)(BLI_Iterator *iter);
32 typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in);
33
34 #define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance) \
35 {                                                                                    \
36         _type _instance;                                                                 \
37         IteratorCb callback_end_func = callback_end;                                     \
38         BLI_Iterator iter_macro;                                                         \
39         iter_macro.skip = false;                                                         \
40         iter_macro.valid = true;                                                         \
41         for (callback_begin(&iter_macro, (_data_in));                                    \
42              iter_macro.valid;                                                           \
43              callback_next(&iter_macro))                                                 \
44         {                                                                                \
45                 if (iter_macro.skip) {                                                       \
46                         iter_macro.skip = false;                                                 \
47                         continue;                                                                \
48                 }                                                                            \
49                 _instance = (_type ) iter_macro.current;
50
51 #define ITER_END                                                                     \
52         }                                                                                \
53         callback_end_func(&iter_macro);                                                  \
54 } ((void)0)
55
56 #endif /* __BLI_ITERATOR_H__ */