~ubuntu-branches/ubuntu/edgy/lynx/edgy

« back to all changes in this revision

Viewing changes to WWW/Library/Implementation/HTList.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-16 12:14:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040916121410-cz1gu92c4nqfeyrg
Tags: upstream-2.8.5
ImportĀ upstreamĀ versionĀ 2.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*              List object
 
3
**
 
4
**      The list object is a generic container for storing collections
 
5
**      of things in order.
 
6
*/
 
7
#ifndef HTLIST_H
 
8
#define HTLIST_H
 
9
 
 
10
#ifndef HTUTILS_H
 
11
#include <HTUtils.h>
 
12
#endif
 
13
 
 
14
typedef struct _HTList HTList;
 
15
 
 
16
struct _HTList {
 
17
        void *          object;
 
18
        HTList *        next;
 
19
};
 
20
 
 
21
 
 
22
/*      Fast macro to traverse a list.  Call it first with copy of the list
 
23
**      header.  It returns the first object and increments the passed list
 
24
**      pointer.  Call it with the same variable until it returns NULL.
 
25
*/
 
26
#define HTList_nextObject(me) \
 
27
        ((me) && ((me) = (me)->next) ? (me)->object : NULL)
 
28
 
 
29
 
 
30
/*      Macro to find object pointed to by the head (returns NULL
 
31
**      if list is empty, OR if it doesn't exist - Yuk!)
 
32
*/
 
33
#define HTList_lastObject(me) \
 
34
        ((me) && (me)->next ? (me)->next->object : NULL)
 
35
 
 
36
 
 
37
/*      Macro to check if a list is empty (or doesn't exist - Yuk!)
 
38
*/
 
39
#define HTList_isEmpty(me) ((me) ? ((me)->next == NULL) : YES)
 
40
 
 
41
 
 
42
/*      Create list.
 
43
*/
 
44
extern HTList * HTList_new NOPARAMS;
 
45
 
 
46
 
 
47
/*      Delete list.
 
48
*/
 
49
extern void HTList_delete PARAMS((
 
50
        HTList *        me));
 
51
 
 
52
/*      Reverse a list.
 
53
*/
 
54
extern HTList * HTList_reverse PARAMS((
 
55
        HTList *        start));
 
56
 
 
57
/*      Append two lists, making second list empty.
 
58
*/
 
59
extern HTList * HTList_appendList PARAMS((
 
60
        HTList *        start,
 
61
        HTList *        tail));
 
62
 
 
63
 
 
64
/*      Add object to START of list (so it is pointed to by the head).
 
65
*/
 
66
extern void HTList_addObject PARAMS((
 
67
        HTList *        me,
 
68
        void *          newObject));
 
69
 
 
70
 
 
71
/*      Append object to END of list (furthest from the head).
 
72
*/
 
73
extern void HTList_appendObject PARAMS((
 
74
        HTList *        me,
 
75
        void *          newObject));
 
76
 
 
77
 
 
78
/*      Insert an object into the list at a specified position.
 
79
**      If position is 0, this places the object at the head of the list
 
80
**      and is equivalent to HTList_addObject().
 
81
*/
 
82
extern void HTList_insertObjectAt PARAMS((
 
83
        HTList *        me,
 
84
        void *          newObject,
 
85
        int             pos));
 
86
 
 
87
 
 
88
/*      Remove specified object from list.
 
89
*/
 
90
extern BOOL HTList_removeObject PARAMS((
 
91
        HTList *        me,
 
92
        void *          oldObject));
 
93
 
 
94
 
 
95
/*      Remove object at a given position in the list, where 0 is the
 
96
**      object pointed to by the head (returns a pointer to the element
 
97
**      (->object) for the object, and NULL if the list is empty, or
 
98
**      if it doesn't exist - Yuk!).
 
99
*/
 
100
extern void * HTList_removeObjectAt PARAMS((
 
101
        HTList *        me,
 
102
        int             position));
 
103
 
 
104
 
 
105
/*      Remove object from START of list (the Last one inserted
 
106
**      via HTList_addObject(), and pointed to by the head).
 
107
*/
 
108
extern void * HTList_removeLastObject PARAMS((
 
109
        HTList *        me));
 
110
 
 
111
 
 
112
/*      Remove object from END of list (the First one inserted
 
113
**      via HTList_addObject(), and furthest from the head).
 
114
*/
 
115
extern void * HTList_removeFirstObject PARAMS((
 
116
        HTList *        me));
 
117
 
 
118
 
 
119
/*      Determine total number of objects in the list,
 
120
**      not counting the head.
 
121
*/
 
122
extern int HTList_count PARAMS((
 
123
        HTList *        me));
 
124
 
 
125
 
 
126
/*      Determine position of an object in the list (a value of 0
 
127
**      means it is pointed to by the head; returns -1 if not found).
 
128
*/
 
129
extern int HTList_indexOf PARAMS((
 
130
        HTList *        me,
 
131
        void *          object));
 
132
 
 
133
 
 
134
/*      Return pointer to the object at a specified position in the list,
 
135
**      where 0 is the object pointed to by the head (returns NULL if
 
136
**      the list is empty, or if it doesn't exist - Yuk!).
 
137
*/
 
138
extern void * HTList_objectAt PARAMS((
 
139
        HTList *        me,
 
140
        int             position));
 
141
 
 
142
/*      Link object to START of list (so it is pointed to by the head).
 
143
 *
 
144
 *      Unlike HTList_addObject(), it does not malloc memory for HTList entry,
 
145
 *      it use already allocated memory which should not be free'd by any
 
146
 *      list operations (optimization).
 
147
 */
 
148
extern void HTList_linkObject PARAMS((
 
149
        HTList *        me,
 
150
        void *          newObject,
 
151
        HTList *        newNode));
 
152
 
 
153
/*      Unlink object from START of list (the Last one inserted
 
154
 *      via HTList_linkObject(), and pointed to by the head).
 
155
 *      It does not free memory.
 
156
 */
 
157
extern void * HTList_unlinkLastObject PARAMS((
 
158
        HTList *        me));
 
159
 
 
160
/*      Unlink specified object from list.
 
161
 *      It does not free memory.
 
162
 */
 
163
extern BOOL HTList_unlinkObject PARAMS((
 
164
        HTList *        me,
 
165
        void *          oldObject));
 
166
 
 
167
#endif /* HTLIST_H */