]> git.ipfire.org Git - thirdparty/gcc.git/blob - libbanshee/engine/list.h
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / libbanshee / engine / list.h
1 /*
2 * Copyright (c) 2000-2001
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31 #ifndef LIST_H
32 #define LIST_H
33
34 #include <regions.h>
35 #include "bool.h"
36
37 typedef void *list_data;
38 typedef void (*app_fn) (void *);
39 typedef bool (*eq_fn)(const void *);
40 typedef int (*comparator_fn)(const void *,const void *);
41
42 struct list;
43
44 typedef struct list_node *list_node;
45
46 struct list_scanner
47 {
48 struct list *l;
49 list_node cur;
50 }; /* Opaque type. Do not modify fields */
51
52
53 struct list *new_list(region r);
54 int list_size(struct list *a);
55 struct list *list_cons(void *data, struct list *a);
56 struct list *list_append(struct list *a, struct list *b);
57 struct list *list_app(struct list *a,app_fn app);
58 void *list_find(struct list *a,eq_fn eq);
59 void *list_head(struct list *a);
60 struct list *list_tail(struct list *a);
61 struct list *list_filter(region r,struct list *a,eq_fn eq);
62 struct list *list_filter2(struct list *a,eq_fn eq);
63 struct list *list_keep(struct list *a,eq_fn eq);
64 struct list *list_copy(region r, struct list *a);
65 struct list *list_sort(struct list *a, comparator_fn cmp);
66 struct list *list_merge(struct list *a,struct list *b, comparator_fn cmp);
67 void list_scan(struct list *a,struct list_scanner *scan);
68 bool list_next(struct list_scanner *scan, void **data);
69 bool list_empty(struct list *a);
70 bool list_member(struct list *a, void *data);
71 void list_clear(struct list *a);
72 struct list *list_reverse(struct list *a);
73 struct list *list_from_array(region r,void **data, int length);
74
75 #define DECLARE_OPAQUE_LIST(name,type) \
76 typedef struct list_scanner name ## _scanner; \
77 typedef void (* name ## _app_fn) (type); \
78 typedef bool (* name ## _eq_fn) (const type); \
79 typedef int (* name ## _comparator_fn)(const type,const type); \
80 name new_ ## name(region r); \
81 int name ## _length(name a); \
82 name name ## _cons(type data, name a); \
83 name name ## _append(name a, name b); \
84 name name ## _app(name a, name ## _app_fn app); \
85 type name ## _find(name a, name ## _eq_fn eq); \
86 type name ## _head(name a); \
87 name name ## _tail(name a); \
88 name name ## _filter(region r,name a, name ## _eq_fn eq); \
89 name name ## _filter2(name a, name ## _eq_fn eq); \
90 name name ## _keep(name a, name ## _eq_fn eq); \
91 name name ## _copy(region r, name a); \
92 name name ## _sort(name a, name ## _comparator_fn cmp); \
93 name name ## _merge(name a,name b, name ## _comparator_fn cmp); \
94 void name ## _scan(name a, name ##_scanner *scan); \
95 bool name ## _next(name ##_scanner *scan, type *data); \
96 bool name ## _empty(name a); \
97 void name ## _clear(name a); \
98 bool name ## _member(name a, type data); \
99 name name ## _reverse(name a); \
100 name name ## _from_array(region r,type data[], int length);
101
102 #define DECLARE_LIST(name,type) \
103 typedef struct name ## _a *name; \
104 typedef struct list_scanner name ## _scanner; \
105 typedef void (* name ## _app_fn) (type); \
106 typedef bool (* name ## _eq_fn) (const type); \
107 typedef int (* name ## _comparator_fn)(const type,const type); \
108 name new_ ## name(region r); \
109 int name ## _length(name a); \
110 name name ## _cons(type data, name a); \
111 name name ## _append(name a, name b); \
112 name name ## _app(name a, name ## _app_fn app); \
113 type name ## _find(name a, name ## _eq_fn eq); \
114 type name ## _head(name a); \
115 name name ## _tail(name a); \
116 name name ## _filter(region r,name a, name ## _eq_fn eq); \
117 name name ## _filter2(name a, name ## _eq_fn eq); \
118 name name ## _keep(name a, name ## _eq_fn eq); \
119 name name ## _copy(region r, name a); \
120 name name ## _sort(name a, name ## _comparator_fn cmp); \
121 name name ## _merge(name a,name b, name ## _comparator_fn cmp); \
122 void name ## _scan(name a, name ##_scanner *scan); \
123 bool name ## _next(name ##_scanner *scan, type *data); \
124 bool name ## _empty(name a); \
125 void name ## _clear(name a); \
126 bool name ## _member(name a, type data); \
127 name name ## _reverse(name a); \
128 name name ## _from_array(region r,type data[], int length);
129
130 #define DEFINE_LIST(name,type) \
131 name new_ ## name(region r) \
132 { \
133 return (name)new_list(r); \
134 } \
135 int name ## _length(name a) \
136 { \
137 return list_size((struct list *)a); \
138 } \
139 name name ## _cons(type data, name a) \
140 { \
141 return (name)list_cons((void *)data,(struct list *) a ); \
142 }\
143 name name ## _append(name a, name b) \
144 { \
145 return (name)list_append((struct list *)a,(struct list *)b); \
146 } \
147 name name ## _app(name a, name ## _app_fn app) \
148 { \
149 return (name)list_app((struct list *) a, (app_fn) app); \
150 } \
151 type name ## _find(name a, name ## _eq_fn eq) \
152 { \
153 return (type)list_find((struct list *)a, (eq_fn) eq); \
154 } \
155 name name ## _tail(name a) \
156 {\
157 return (name)list_tail((struct list *)a);\
158 }\
159 type name ## _head(name a) \
160 { \
161 return (type)list_head((struct list *)a); \
162 } \
163 name name ## _filter(region r,name a, name ## _eq_fn eq) \
164 { \
165 return (name)list_filter(r,(struct list *)a, (eq_fn) eq); \
166 } \
167 name name ## _keep(name a, name ## _eq_fn eq) \
168 { \
169 return (name)list_keep((struct list *)a, (eq_fn) eq); \
170 } \
171 name name ## _filter2(name a, name ## _eq_fn eq) \
172 { \
173 return (name)list_filter2((struct list *)a, (eq_fn) eq); \
174 } \
175 name name ## _copy(region r, name a) \
176 { \
177 return (name)list_copy(r,(struct list *) a); \
178 } \
179 name name ## _sort(name a, name ## _comparator_fn cmp) \
180 { \
181 return (name)list_sort((struct list *)a,(comparator_fn) cmp); \
182 } \
183 name name ## _merge(name a,name b, name ## _comparator_fn cmp) \
184 { \
185 return (name)list_merge((struct list *)a,(struct list *)b,(comparator_fn)cmp); \
186 } \
187 void name ## _scan(name a, name ##_scanner *scan) \
188 { \
189 list_scan((struct list *)a,(struct list_scanner *)scan);\
190 }\
191 bool name ## _next(name ##_scanner *scan, type *data) \
192 { \
193 return list_next((struct list_scanner *)scan, (void **)data); \
194 } \
195 bool name ## _empty(name a) \
196 { \
197 return list_empty((struct list *)a); \
198 } \
199 void name ## _clear(name a) \
200 { \
201 list_clear((struct list *)a); \
202 } \
203 bool name ## _member(name a, type data) \
204 { \
205 return list_member((struct list *)a,(void *)data); \
206 } \
207 name name ## _reverse(name a) \
208 {\
209 return (name)list_reverse((struct list *)a);\
210 }\
211 name name ## _from_array(region r,type data[], int length) \
212 {\
213 return (name)list_from_array(r,(void **)data,length); \
214 }\
215
216 #endif /* LIST_H */