Releasing version 3-2014010504
[notion/jeffpc.git] / libtu / ptrlist.h
blob70da547af77b8e67ec882d8e6294d99524aa2d32
1 /*
2 * libtu/ptrlist.h
4 * Copyright (c) Tuomo Valkonen 1999-2005.
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 */
10 #ifndef LIBTU_PTRLIST_H
11 #define LIBTU_PTRLIST_H
13 #include "types.h"
14 #include "iterable.h"
17 INTRSTRUCT(PtrList);
20 DECLSTRUCT(PtrList){
21 void *ptr;
22 PtrList *next, *prev;
26 typedef PtrList* PtrListIterTmp;
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)
32 #define FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, TMP) \
33 FOR_ALL_ITER(ptrlist_iter_init, (TYPE)ptrlist_iter, VAR, LL, &(TMP))
35 #define FOR_ALL_ON_PTRLIST_REV(TYPE, VAR, LL, TMP) \
36 FOR_ALL_ITER(ptrlist_iter_rev_init, \
37 (TYPE)ptrlist_iter_rev, VAR, LL, &(TMP))
39 #define FOR_ALL_ON_PTRLIST_UNSAFE(TYPE, VAR, LL) \
40 FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, ptrlist_iter_tmp)
42 extern PtrListIterTmp ptrlist_iter_tmp;
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);
48 extern bool ptrlist_remove(PtrList **ptrlist, void *ptr);
49 extern bool ptrlist_contains(PtrList *ptrlist, void *ptr);
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);
55 extern void *ptrlist_take_first(PtrList **ptrlist);
56 extern void *ptrlist_take_last(PtrList **ptrlist);
58 #endif /* LIBTU_PTRLIST_H */