Consistency fixes
[notion.git] / libtu / objlist.h
blob62533cb558f7e336fd7323e9882bfd4a71a9ed83
1 /*
2 * libtu/objlist.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_OBJLIST_H
11 #define LIBTU_OBJLIST_H
13 #include "types.h"
14 #include "iterable.h"
15 #include "obj.h"
18 INTRSTRUCT(ObjList);
21 DECLSTRUCT(ObjList){
22 Watch watch; /* Must be kept at head of structure */
23 ObjList *next, *prev;
24 ObjList **list;
28 typedef ObjList* ObjListIterTmp;
30 #define OBJLIST_FIRST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->watch.obj)
31 #define OBJLIST_LAST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->prev->watch.obj)
32 #define OBJLIST_EMPTY(LIST) objlist_empty(LIST)
34 #define FOR_ALL_ON_OBJLIST(TYPE, VAR, LL, TMP) \
35 FOR_ALL_ITER(objlist_iter_init, (TYPE)objlist_iter, VAR, LL, &(TMP))
37 #define FOR_ALL_ON_OBJLIST_REV(TYPE, VAR, LL, TMP) \
38 FOR_ALL_ITER(objlist_iter_rev_init, \
39 (TYPE)objlist_iter_rev, VAR, LL, &(TMP))
41 #define FOR_ALL_ON_OBJLIST_UNSAFE(TYPE, VAR, LL) \
42 FOR_ALL_ON_OBJLIST(TYPE, VAR, LL, objlist_iter_tmp)
44 extern ObjListIterTmp objlist_iter_tmp;
46 extern bool objlist_insert_last(ObjList **objlist, Obj *obj);
47 extern bool objlist_insert_first(ObjList **objlist, Obj *obj);
48 extern bool objlist_reinsert_last(ObjList **objlist, Obj *obj);
49 extern bool objlist_reinsert_first(ObjList **objlist, Obj *obj);
50 extern bool objlist_remove(ObjList **objlist, Obj *obj);
51 extern bool objlist_contains(ObjList *objlist, Obj *obj);
52 extern void objlist_clear(ObjList **objlist);
53 extern void objlist_iter_init(ObjListIterTmp *state, ObjList *objlist);
54 extern Obj *objlist_iter(ObjListIterTmp *state);
55 extern void objlist_iter_rev_init(ObjListIterTmp *state, ObjList *objlist);
56 extern Obj *objlist_iter_rev(ObjListIterTmp *state);
57 extern bool objlist_empty(ObjList *objlist);
58 extern Obj *objlist_take_first(ObjList **objlist);
59 extern Obj *objlist_take_last(ObjList **objlist);
61 #endif /* LIBTU_OBJLIST_H */