libFirm
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
plist.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5 
17 #ifndef FIRM_ADT_PLIST_H
18 #define FIRM_ADT_PLIST_H
19 
20 #include "obst.h"
21 
22 #include "../begin.h"
23 
30 typedef struct plist_element plist_element_t;
31 typedef struct plist plist_t;
32 
36 struct plist {
38  struct obstack *obst;
39 
41  unsigned foreign_obstack : 1;
42 
44  plist_element_t *first_element;
45 
47  plist_element_t *last_element;
48 
51 
57  plist_element_t* first_free_element;
58 };
59 
63 struct plist_element {
64  plist_element_t *next;
65  plist_element_t *prev;
66  void *data;
67 };
68 
73 FIRM_API plist_t *plist_new(void);
74 
81 FIRM_API plist_t *plist_obstack_new(struct obstack *obst);
82 
88 FIRM_API void plist_free(plist_t *list);
89 
95 #define plist_count(list) \
96  ((list)->element_count)
97 
103 FIRM_API void plist_insert_back(plist_t *list, void *value);
104 
110 FIRM_API void plist_insert_front(plist_t *list, void *value);
111 
120 FIRM_API void plist_insert_before(plist_t *list, plist_element_t *element, void *value);
121 
130 FIRM_API void plist_insert_after(plist_t *list, plist_element_t *element, void *value);
131 
138 FIRM_API int plist_has_value(plist_t *list, void *value);
139 
146 FIRM_API plist_element_t *plist_find_value(plist_t *list, void *value);
147 
154 FIRM_API void plist_erase(plist_t *list, plist_element_t *element);
155 
160 FIRM_API void plist_clear(plist_t *list);
161 
167 #define plist_first(list) \
168  ((list)->first_element)
169 
175 #define plist_last(list) \
176  ((list)->last_element)
177 
184 #define plist_element_has_next(element) \
185  ((element)->next != NULL)
186 
193 #define plist_element_has_prev(element) \
194  ((element)->prev != NULL)
195 
202 #define plist_element_get_next(element) \
203  ((element)->next)
204 
211 #define plist_element_get_prev(element) \
212  ((element)->prev)
213 
219 #define plist_element_get_value(element) \
220  ((element)->data)
221 
225 #define foreach_plist(list, el) \
226  for (plist_element_t *el = plist_first(list); el; el = plist_element_get_next(el))
227 
230 #include "../end.h"
231 
232 #endif
int element_count
Current number of elements in the list.
Definition: plist.h:50
void plist_erase(plist_t *list, plist_element_t *element)
Erases the specified element from the pointer list.
int plist_has_value(plist_t *list, void *value)
Checks if list has an element with the given data pointer.
plist_element_t * first_free_element
First element in the free list.
Definition: plist.h:57
plist_element_t * last_element
Last element in the list.
Definition: plist.h:47
void plist_insert_after(plist_t *list, plist_element_t *element, void *value)
Inserts an element into a pointer list after the specified element, which must be non null...
plist_t * plist_new(void)
Creates a new pointer list and initializes it.
void plist_insert_before(plist_t *list, plist_element_t *element, void *value)
Inserts an element into a pointer list before the specified element, which must be non null...
void plist_free(plist_t *list)
Frees the passed pointer list.
plist_element_t * next
next element in double linked list
Definition: plist.h:64
plist_t * plist_obstack_new(struct obstack *obst)
Creates a new pointer list and initializes it.
plist_element_t * prev
previous element in double linked list
Definition: plist.h:65
void * data
element data
Definition: plist.h:66
plist_element_t * first_element
First element in the list.
Definition: plist.h:44
plist_element_t * plist_find_value(plist_t *list, void *value)
Tries to find list element associated to the given data pointer.
struct obstack * obst
The obstack used for all allocations.
Definition: plist.h:38
void plist_insert_back(plist_t *list, void *value)
Inserts an element at the back of a pointer list.
void plist_insert_front(plist_t *list, void *value)
Inserts an element at the front of a pointer list.
void plist_clear(plist_t *list)
Erases all elements from the specified pointer list.
The plist data type.
Definition: plist.h:36
An element in the pointer list.
Definition: plist.h:63
unsigned foreign_obstack
Set to 1 if plist uses a foreign obstack.
Definition: plist.h:41