objlist.h

Sun, 06 May 2007 16:05:59 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 06 May 2007 16:05:59 +0200
changeset 111
7d1dccdd7215
parent 101
50525dab6c8e
permissions
-rw-r--r--

Some list code improvements

60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
1 /*
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
2 * libtu/objlist.h
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
3 *
91
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2005.
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
5 *
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
6 * You may distribute and modify this library under the terms of either
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
8 */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
9
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
10 #ifndef LIBTU_OBJLIST_H
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
11 #define LIBTU_OBJLIST_H
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
12
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
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
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
15 #include "obj.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
16
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
17
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
18 INTRSTRUCT(ObjList);
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
19
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
20
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
21 DECLSTRUCT(ObjList){
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
22 Watch watch; /* Must be kept at head of structure */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
23 ObjList *next, *prev;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
24 ObjList **list;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
25 };
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
26
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
27
91
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
28 typedef ObjList* ObjListIterTmp;
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
29
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
30 #define OBJLIST_FIRST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->watch.obj)
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
31 #define OBJLIST_LAST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->prev->watch.obj)
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
32 #define OBJLIST_EMPTY(LIST) objlist_empty(LIST)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
33
91
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
34 #define FOR_ALL_ON_OBJLIST(TYPE, VAR, LL, TMP) \
93
5f72042eb91c Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
35 FOR_ALL_ITER(objlist_iter_init, (TYPE)objlist_iter, VAR, LL, &(TMP))
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
36
93
5f72042eb91c Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
37 #define FOR_ALL_ON_OBJLIST_REV(TYPE, VAR, LL, TMP) \
5f72042eb91c Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
38 FOR_ALL_ITER(objlist_iter_rev_init, \
5f72042eb91c Increased FOR_ALL macro reuse.
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
39 (TYPE)objlist_iter_rev, VAR, LL, &(TMP))
91
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
40
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
41 #define FOR_ALL_ON_OBJLIST_UNSAFE(TYPE, VAR, LL) \
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
42 FOR_ALL_ON_OBJLIST(TYPE, VAR, LL, objlist_iter_tmp)
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
43
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
44 extern ObjListIterTmp objlist_iter_tmp;
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
45
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
46 extern bool objlist_insert_last(ObjList **objlist, Obj *obj);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
47 extern bool objlist_insert_first(ObjList **objlist, Obj *obj);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
48 extern bool objlist_reinsert_last(ObjList **objlist, Obj *obj);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
49 extern bool objlist_reinsert_first(ObjList **objlist, Obj *obj);
101
50525dab6c8e *list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents: 94
diff changeset
50 extern bool objlist_remove(ObjList **objlist, Obj *obj);
111
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
51 extern bool objlist_contains(ObjList *objlist, Obj *obj);
91
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
52 extern void objlist_clear(ObjList **objlist);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
53 extern void objlist_iter_init(ObjListIterTmp *state, ObjList *objlist);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
54 extern Obj *objlist_iter(ObjListIterTmp *state);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
55 extern void objlist_iter_rev_init(ObjListIterTmp *state, ObjList *objlist);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
56 extern Obj *objlist_iter_rev(ObjListIterTmp *state);
817f90f58aec ObjList changes.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
57 extern bool objlist_empty(ObjList *objlist);
92
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 91
diff changeset
58 extern Obj *objlist_take_first(ObjList **objlist);
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 91
diff changeset
59 extern Obj *objlist_take_last(ObjList **objlist);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
61 #endif /* LIBTU_OBJLIST_H */

mercurial