[409] | 1 | /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc. |
---|
| 2 | See the COPYRIGHT file for more information. */ |
---|
| 3 | #ifndef OCLIST_H |
---|
| 4 | #define OCLIST_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 ocelem; |
---|
| 15 | |
---|
| 16 | EXTERNC int oclistnull(ocelem); |
---|
| 17 | |
---|
| 18 | typedef struct OClist { |
---|
| 19 | unsigned int alloc; |
---|
| 20 | unsigned int length; |
---|
| 21 | ocelem* content; |
---|
| 22 | } OClist; |
---|
| 23 | |
---|
| 24 | EXTERNC OClist* oclistnewn(int); |
---|
| 25 | EXTERNC int oclistfree(OClist*); |
---|
| 26 | EXTERNC int oclistsetalloc(OClist*,unsigned int); |
---|
| 27 | EXTERNC int oclistsetlength(OClist*,unsigned int); |
---|
| 28 | |
---|
| 29 | /* Set the ith element */ |
---|
| 30 | EXTERNC int oclistset(OClist*,unsigned int,ocelem); |
---|
| 31 | /* Get value at position i */ |
---|
| 32 | EXTERNC ocelem oclistget(OClist*,unsigned int);/* Return the ith element of l */ |
---|
| 33 | /* Insert at position i; will push up elements i..|seq|. */ |
---|
| 34 | EXTERNC int oclistinsert(OClist*,unsigned int,ocelem); |
---|
| 35 | /* Remove element at position i; will move higher elements down */ |
---|
| 36 | EXTERNC ocelem oclistremove(OClist* l, unsigned int i); |
---|
| 37 | |
---|
| 38 | /* Tail operations */ |
---|
| 39 | EXTERNC int oclistpush(OClist*,ocelem); /* Add at Tail */ |
---|
| 40 | EXTERNC ocelem oclistpop(OClist*); |
---|
| 41 | EXTERNC ocelem oclisttop(OClist*); |
---|
| 42 | |
---|
| 43 | /* Duplicate and return the content (null terminate) */ |
---|
| 44 | EXTERNC ocelem* oclistdup(OClist*); |
---|
| 45 | |
---|
| 46 | /* Look for value match */ |
---|
| 47 | EXTERNC int oclistcontains(OClist*, ocelem); |
---|
| 48 | |
---|
| 49 | /* Following are always "in-lined"*/ |
---|
| 50 | #define oclistnew() oclistnewn(0) |
---|
| 51 | #define oclistclear(l) oclistsetlength((l),0U) |
---|
| 52 | #define oclistextend(l,len) oclistsetalloc((l),(len)+(l->alloc)) |
---|
| 53 | #define oclistcontents(l) ((l)->content) |
---|
| 54 | #define oclistlength(l) ((l)?(l)->length:0U) |
---|
| 55 | |
---|
| 56 | #endif /*OCLIST_H*/ |
---|
| 57 | |
---|