1 | /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc. |
---|
2 | See the COPYRIGHT file for more information. */ |
---|
3 | #ifndef NCLIST_H |
---|
4 | #define NCLIST_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 | typedef unsigned long ncelem; |
---|
15 | |
---|
16 | EXTERNC int nclistnull(ncelem); |
---|
17 | |
---|
18 | typedef struct NClist { |
---|
19 | unsigned int alloc; |
---|
20 | unsigned int length; |
---|
21 | ncelem* content; |
---|
22 | } NClist; |
---|
23 | |
---|
24 | EXTERNC NClist* nclistnew(void); |
---|
25 | EXTERNC int nclistfree(NClist*); |
---|
26 | EXTERNC int nclistsetalloc(NClist*,unsigned int); |
---|
27 | EXTERNC int nclistsetlength(NClist*,unsigned int); |
---|
28 | |
---|
29 | /* Set the ith element */ |
---|
30 | EXTERNC int nclistset(NClist*,unsigned int,ncelem); |
---|
31 | /* Get value at position i */ |
---|
32 | EXTERNC ncelem nclistget(NClist*,unsigned int);/* Return the ith element of l */ |
---|
33 | /* Insert at position i; will push up elements i..|seq|. */ |
---|
34 | EXTERNC int nclistinsert(NClist*,unsigned int,ncelem); |
---|
35 | /* Remove element at position i; will move higher elements down */ |
---|
36 | EXTERNC ncelem nclistremove(NClist* l, unsigned int i); |
---|
37 | |
---|
38 | /* Tail operations */ |
---|
39 | EXTERNC int nclistpush(NClist*,ncelem); /* Add at Tail */ |
---|
40 | EXTERNC ncelem nclistpop(NClist*); |
---|
41 | EXTERNC ncelem nclisttop(NClist*); |
---|
42 | |
---|
43 | /* Duplicate and return the content (null terminate) */ |
---|
44 | EXTERNC ncelem* nclistdup(NClist*); |
---|
45 | |
---|
46 | /* Look for value match */ |
---|
47 | EXTERNC int nclistcontains(NClist*, ncelem); |
---|
48 | |
---|
49 | /* Remove element by value; only removes first encountered */ |
---|
50 | EXTERNC int nclistelemremove(NClist* l, ncelem elem); |
---|
51 | |
---|
52 | |
---|
53 | /* remove duplicates */ |
---|
54 | EXTERNC int nclistunique(NClist*); |
---|
55 | |
---|
56 | /* Create a clone of a list */ |
---|
57 | EXTERNC NClist* nclistclone(NClist*); |
---|
58 | |
---|
59 | /* Following are always "in-lined"*/ |
---|
60 | #define nclistclear(l) nclistsetlength((l),0U) |
---|
61 | #define nclistextend(l,len) nclistsetalloc((l),(len)+(l->alloc)) |
---|
62 | #define nclistcontents(l) ((l)->content) |
---|
63 | #define nclistlength(l) ((l)?(l)->length:0U) |
---|
64 | |
---|
65 | #endif /*NCLIST_H*/ |
---|
66 | |
---|
67 | |
---|