Initial commit of pristine erwise source
[erwise] / Cl / WWWLibrary / HTList.h
1 /*              List object
2 **
3 **      The list object is a generic container for storing collections
4 **      of things in order.
5 */
6 #ifndef HTLIST_H
7 #define HTLIST_H
8
9 #include "HTUtils.h"  /* for BOOL type and PARAMS and ARGS*/
10
11 typedef struct _HTList HTList;
12
13 struct _HTList {
14   void * object;
15   HTList * next;
16 };
17
18 #ifdef SHORT_NAMES
19 #define HTList_new                      HTLiNew
20 #define HTList_delete                   HTLiDele
21 #define HTList_addObject                HTLiAdOb
22 #define HTList_removeObject             HTLiReOb
23 #define HTList_removeLastObject         HTLiReLa
24 #define HTList_removeFirstObject        HTLiReFi
25 #define HTList_count                    HTLiCoun
26 #define HTList_indexOf                  HTLiInOf
27 #define HTList_objectAt                 HTLiObAt
28 #endif
29
30 extern HTList * HTList_new NOPARAMS;
31 extern void     HTList_delete PARAMS((HTList *this));
32 extern void     HTList_addObject PARAMS((HTList *this, void *newObject));
33 extern BOOL     HTList_removeObject PARAMS((HTList *this, void *oldObject));
34 extern void *   HTList_removeLastObject PARAMS((HTList *this));
35 extern void *   HTList_removeFirstObject PARAMS((HTList *this));
36 #define         HTList_isEmpty(this) (this ? this->next == NULL : YES)
37 extern int      HTList_count PARAMS((HTList *this));
38 extern int      HTList_indexOf PARAMS((HTList *this, void *object));
39 #define         HTList_lastObject(this) \
40   (this && this->next ? this->next->object : NULL)
41 extern void *   HTList_objectAt PARAMS((HTList *this, int position));
42
43 /* Fast macro to traverse the list. Call it first with copy of list header :
44    it returns the first object and increments the passed list pointer.
45    Call it with the same variable until it returns NULL. */
46 #define HTList_nextObject(this) \
47   (this && (this = this->next) ? this->object : NULL)
48
49 #endif /* HTLIST_H */