13b71e5e5aac1fd30ea5b98a68167b2740575995
[libfirm] / include / libfirm / adt / iterator.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Iterators for the several collection types used in firm.
23  *          Useful for formatted and unified dumping of collections of objects.
24  * @author  Sebastian Hack
25  * @date    29.11.2004
26  * @version $Id$
27  */
28 #ifndef FIRM_ADT_ITERATOR_H
29 #define FIRM_ADT_ITERATOR_H
30
31 #include "fourcc.h"
32
33 /**
34  * The iterator magic word.
35  */
36 #define ITERATOR_MAGIC FOURCC('I', 'T', 'E', 'R')
37
38 /**
39  * Check, if some memory object appears to be an iterator.
40  * @param ptr Some memory.
41  * @return 1, if that memory area appears to be an iterator, 0 if not.
42  */
43 #define is_iterator(ptr) (((const iterator_t *) (ptr))->magic == ITERATOR_MAGIC)
44
45 typedef struct _iterator_t {
46         unsigned magic;
47         void *(*start)(void *collection);
48         void *(*next)(void *collection, void *curr);
49         void (*finish)(void *collection, void *curr);
50 } iterator_t;
51
52 /**
53  * An iterator implementation for linked lists.
54  */
55 extern const iterator_t *list_iterator;
56
57 /**
58  * An iterator implementation for psets.
59  */
60 extern const iterator_t *pset_iterator;
61
62 #endif