Mon, 20 Apr 2020 10:14:32 -0500
Convert README to markdown
60 | 1 | /* |
90 | 2 | * libtu/ptrlist.h |
60 | 3 | * |
90 | 4 | * Copyright (c) Tuomo Valkonen 1999-2005. |
60 | 5 | * |
6 | * You may distribute and modify this library under the terms of either | |
7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. | |
8 | */ | |
9 | ||
90 | 10 | #ifndef LIBTU_PTRLIST_H |
11 | #define LIBTU_PTRLIST_H | |
60 | 12 | |
13 | #include "types.h" | |
94
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
93
diff
changeset
|
14 | #include "iterable.h" |
60 | 15 | |
16 | ||
90 | 17 | INTRSTRUCT(PtrList); |
60 | 18 | |
19 | ||
90 | 20 | DECLSTRUCT(PtrList){ |
21 | void *ptr; | |
22 | PtrList *next, *prev; | |
60 | 23 | }; |
24 | ||
25 | ||
90 | 26 | typedef PtrList* PtrListIterTmp; |
88 | 27 | |
90 | 28 | #define PTRLIST_FIRST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->ptr) |
29 | #define PTRLIST_LAST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->prev->ptr) | |
30 | #define PTRLIST_EMPTY(LIST) ((LIST)==NULL) | |
60 | 31 | |
93
5f72042eb91c
Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents:
92
diff
changeset
|
32 | #define FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, TMP) \ |
5f72042eb91c
Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents:
92
diff
changeset
|
33 | FOR_ALL_ITER(ptrlist_iter_init, (TYPE)ptrlist_iter, VAR, LL, &(TMP)) |
5f72042eb91c
Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents:
92
diff
changeset
|
34 | |
5f72042eb91c
Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents:
92
diff
changeset
|
35 | #define FOR_ALL_ON_PTRLIST_REV(TYPE, VAR, LL, TMP) \ |
5f72042eb91c
Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents:
92
diff
changeset
|
36 | FOR_ALL_ITER(ptrlist_iter_rev_init, \ |
5f72042eb91c
Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents:
92
diff
changeset
|
37 | (TYPE)ptrlist_iter_rev, VAR, LL, &(TMP)) |
60 | 38 | |
90 | 39 | #define FOR_ALL_ON_PTRLIST_UNSAFE(TYPE, VAR, LL) \ |
40 | FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, ptrlist_iter_tmp) | |
88 | 41 | |
90 | 42 | extern PtrListIterTmp ptrlist_iter_tmp; |
88 | 43 | |
90 | 44 | extern bool ptrlist_insert_last(PtrList **ptrlist, void *ptr); |
45 | extern bool ptrlist_insert_first(PtrList **ptrlist, void *ptr); | |
46 | extern bool ptrlist_reinsert_last(PtrList **ptrlist, void *ptr); | |
47 | extern bool ptrlist_reinsert_first(PtrList **ptrlist, void *ptr); | |
101
50525dab6c8e
*list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents:
94
diff
changeset
|
48 | extern bool ptrlist_remove(PtrList **ptrlist, void *ptr); |
111 | 49 | extern bool ptrlist_contains(PtrList *ptrlist, void *ptr); |
90 | 50 | extern void ptrlist_clear(PtrList **ptrlist); |
51 | extern void ptrlist_iter_init(PtrListIterTmp *state, PtrList *ptrlist); | |
52 | extern void *ptrlist_iter(PtrListIterTmp *state); | |
53 | extern void ptrlist_iter_rev_init(PtrListIterTmp *state, PtrList *ptrlist); | |
54 | extern void *ptrlist_iter_rev(PtrListIterTmp *state); | |
92
55fcdff5bcea
Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents:
90
diff
changeset
|
55 | extern void *ptrlist_take_first(PtrList **ptrlist); |
55fcdff5bcea
Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents:
90
diff
changeset
|
56 | extern void *ptrlist_take_last(PtrList **ptrlist); |
60 | 57 | |
90 | 58 | #endif /* LIBTU_PTRLIST_H */ |