Make it use fourcc.h and unified naming a little.
[libfirm] / ir / adt / iterator.h
1 /**
2  * Iterators for the several collection types used in firm.
3  * Useful for formatted and unified dumping of collections of objects.
4  * @author Sebastian Hack
5  * @date 29.11.2004
6  */
7 #ifndef _ITERATOR_H
8 #define _ITERATOR_H
9
10 #include "fourcc.h"
11
12 #define ITERATOR_MAGIC FOURCC('I', 'T', 'E', 'R')
13
14 /**
15  * Check, if some memory object appears to be an iterator.
16  * @param ptr Some memory.
17  * @return 1, if that memory area appears to be an iterator, 0 if not.
18  */
19 #define is_iterator(ptr) (((const iterator_t *) (ptr))->magic == ITERATOR_MAGIC)
20
21 typedef struct _iterator_t {
22         unsigned magic;
23         void *(*start)(void *collection);
24         void *(*next)(void *collection, void *curr);
25         void (*finish)(void *collection, void *curr);
26 } iterator_t;
27
28 /**
29  * An iterator implementation for linked lists.
30  */
31 extern const iterator_t *list_iterator;
32
33 /**
34  * An iterator implementation for psets.
35  */
36 extern const iterator_t *pset_iterator;
37
38 #endif