File: iterator.h

package info (click to toggle)
muon-meson 0.5.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,532 kB
  • sloc: ansic: 67,766; python: 4,391; cpp: 1,983; sh: 709; javascript: 570; asm: 226; xml: 67; objc: 36; makefile: 29; modula3: 8; f90: 7
file content (24 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * SPDX-FileCopyrightText: Stone Tickle <lattis@mochiro.moe>
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef MUON_ITERATORS_H
#define MUON_ITERATORS_H

enum iteration_result {
	ir_err,
	ir_cont,
	ir_done,
};

typedef enum iteration_result (*iterator_func)(void *ctx, void *val);

#define for_iter_(__ctx, __iter_type, __val, __iter)                                                    \
	struct iter_##__iter_type __iter = { 0 };                                                              \
	for (__val = iter_next_##__iter_type(__ctx, &__iter); iter_has_next_##__iter_type(__ctx, &__iter); \
		__val = iter_next_##__iter_type(__ctx, &__iter))

#define for_iter(__iter_type, __ctx, __val) for_iter_(__ctx, __iter_type, __val, CONCAT(__iter, __LINE__))

#endif