libFirm
plist.h
Go to the documentation of this file.
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 
31 #ifndef FIRM_ADT_PLIST_H
32 #define FIRM_ADT_PLIST_H
33 
34 #include <stddef.h>
35 #include "obst.h"
36 
37 #include "../begin.h"
38 
39 typedef struct plist_element plist_element_t;
40 typedef struct plist plist_t;
41 
45 struct plist {
47  struct obstack *obst;
48 
50  unsigned foreign_obstack : 1;
51 
53  plist_element_t *first_element;
54 
56  plist_element_t *last_element;
57 
60 
66  plist_element_t* first_free_element;
67 };
68 
72 struct plist_element {
73  plist_element_t *next;
74  plist_element_t *prev;
75  void *data;
76 };
77 
82 FIRM_API plist_t *plist_new(void);
83 
90 FIRM_API plist_t *plist_obstack_new(struct obstack *obst);
91 
97 FIRM_API void plist_free(plist_t *list);
98 
104 #define plist_count(list) \
105  ((list)->element_count)
106 
112 FIRM_API void plist_insert_back(plist_t *list, void *value);
113 
119 FIRM_API void plist_insert_front(plist_t *list, void *value);
120 
129 FIRM_API void plist_insert_before(plist_t *list, plist_element_t *element, void *value);
130 
139 FIRM_API void plist_insert_after(plist_t *list, plist_element_t *element, void *value);
140 
147 FIRM_API int plist_has_value(plist_t *list, void *value);
148 
155 FIRM_API plist_element_t *plist_find_value(plist_t *list, void *value);
156 
163 FIRM_API void plist_erase(plist_t *list, plist_element_t *element);
164 
169 FIRM_API void plist_clear(plist_t *list);
170 
176 #define plist_first(list) \
177  ((list)->first_element)
178 
184 #define plist_last(list) \
185  ((list)->last_element)
186 
193 #define plist_element_has_next(element) \
194  ((element)->next != NULL)
195 
202 #define plist_element_has_prev(element) \
203  ((element)->prev != NULL)
204 
211 #define plist_element_get_next(element) \
212  ((element)->next)
213 
220 #define plist_element_get_prev(element) \
221  ((element)->prev)
222 
228 #define plist_element_get_value(element) \
229  ((element)->data)
230 
234 #define foreach_plist(list, el) \
235  for (el = plist_first(list); el; el = plist_element_get_next(el))
236 
237 #include "../end.h"
238 
239 #endif