1 /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
2    See the COPYRIGHT file for more information. */
3 #ifndef LIST_H
4 #define LIST_H 1
5 
6 /* Define the type of the elements in the list*/
7 
8 #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
9 #define EXTERNC extern "C"
10 #else
11 #define EXTERNC extern
12 #endif
13 
14 EXTERNC int listnull(void*);
15 
16 typedef struct List {
17   unsigned long alloc;
18   unsigned long length;
19   void** content;
20 } List;
21 
22 EXTERNC List* listnew(void);
23 EXTERNC int listfree(List*);
24 EXTERNC int listsetalloc(List*,unsigned long);
25 EXTERNC int listsetlength(List*,unsigned long);
26 
27 /* Set the ith element */
28 EXTERNC int listset(List*,unsigned long,void*);
29 /* Get value at position i */
30 EXTERNC void* listget(List*,unsigned long);/* Return the ith element of l */
31 /* Insert at position i; will push up elements i..|seq|. */
32 EXTERNC int listinsert(List*,unsigned long,void*);
33 /* Remove element at position i; will move higher elements down */
34 EXTERNC void* listremove(List* l, unsigned long i);
35 
36 /* Tail operations */
37 EXTERNC int listpush(List*,void*); /* Add at Tail */
38 EXTERNC void* listpop(List*);
39 EXTERNC void* listtop(List*);
40 
41 /* Duplicate and return the content (null terminate) */
42 EXTERNC void** listdup(List*);
43 
44 /* Look for value match */
45 EXTERNC int listcontains(List*, void*);
46 
47 /* Remove element by value; only removes first encountered */
48 EXTERNC int listelemremove(List* l, void* elem);
49 
50 /* remove duplicates */
51 EXTERNC int listunique(List*);
52 
53 /* Create a clone of a list */
54 EXTERNC List* listclone(List*);
55 
56 /* Following are always "in-lined"*/
57 #define listclear(l) listsetlength((l),0)
58 #define listextend(l,len) listsetalloc((l),(len)+(l->alloc))
59 #define listcontents(l)  ((l)==NULL?NULL:(l)->content)
60 #define listlength(l)  ((l)==NULL?0:(int)(l)->length)
61 
62 #endif /*LIST_H*/
63