1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
<HTML>
<HEAD>
<TITLE>List object for libwww</TITLE>
<NEXTID N="z3">
</HEAD>
<BODY>
<H1>List object</H1>The list object is a generic container
for storing collections of things
in order. In principle it could
be implemented in many ways, but
in practice knowing that it is a
linked list is important for speed.
See also the <A
NAME="z2" HREF="#z1">traverse macro</A> for
example.
<PRE>
#ifndef HTLIST_H
#define HTLIST_H
#include "HTUtils.h" /* for BOOL type and PARAMS and ARGS*/
typedef struct _HTList HTList;
struct _HTList {
void * object;
HTList * next;
};
#ifdef SHORT_NAMES
#define HTList_new HTLiNew
#define HTList_delete HTLiDele
#define HTList_addObject HTLiAdOb
#define HTList_removeObject HTLiReOb
#define HTList_removeLastObject HTLiReLa
#define HTList_removeFirstObject HTLiReFi
#define HTList_count HTLiCoun
#define HTList_indexOf HTLiInOf
#define HTList_objectAt HTLiObAt
#endif
extern HTList * HTList_new NOPARAMS;
extern void HTList_delete PARAMS((HTList *me));
</PRE>
<H3>Add object to START of list</H3>
<PRE>
extern void HTList_addObject PARAMS((HTList *me, void *newObject));
extern BOOL HTList_removeObject PARAMS((HTList *me, void *oldObject));
extern void * HTList_removeLastObject PARAMS((HTList *me));
extern void * HTList_removeFirstObject PARAMS((HTList *me));
#define HTList_isEmpty(me) (me ? me->next == NULL : YES)
extern int HTList_count PARAMS((HTList *me));
extern int HTList_indexOf PARAMS((HTList *me, void *object));
#define HTList_lastObject(me) \
(me && me->next ? me->next->object : NULL)
extern void * HTList_objectAt PARAMS((HTList *me, int position));
</PRE>
<H3><A
NAME="z1">Traverse list</A></H3>Fast macro to traverse the list.
Call it first with copy of list header
: it returns the first object and
increments the passed list pointer.
Call it with the same variable until
it returns NULL.
<PRE>#define HTList_nextObject(me) \
(me && (me = me->next) ? me->object : NULL)
</PRE>
<H3>Free list</H3>
<PRE>#define HTList_free(x) free(x)
#endif /* HTLIST_H */
</PRE>end</A></BODY>
</HTML>
|