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 extern "C" { 10 #endif 11 12 extern int nclistnull(void*); 13 14 typedef struct NClist { 15 size_t alloc; 16 size_t length; 17 void** content; 18 } NClist; 19 20 extern NClist* nclistnew(void); 21 extern int nclistfree(NClist*); 22 extern int nclistfreeall(NClist*); 23 extern int nclistsetalloc(NClist*,size_t); 24 extern int nclistsetlength(NClist*,size_t); 25 26 /* Set the ith element; will overwrite previous contents; expand if needed */ 27 extern int nclistset(NClist*,size_t,void*); 28 /* Get value at position i */ 29 extern void* nclistget(NClist*,size_t);/* Return the ith element of l */ 30 /* Insert at position i; will push up elements i..|seq|. */ 31 extern int nclistinsert(NClist*,size_t,void*); 32 /* Remove element at position i; will move higher elements down */ 33 extern void* nclistremove(NClist* l, size_t i); 34 35 /* Tail operations */ 36 extern int nclistpush(NClist*,void*); /* Add at Tail */ 37 extern void* nclistpop(NClist*); 38 extern void* nclisttop(NClist*); 39 40 /* Duplicate and return the content (null terminate) */ 41 extern void** nclistdup(NClist*); 42 43 /* Look for value match */ 44 extern int nclistcontains(NClist*, void*); 45 46 /* Remove element by value; only removes first encountered */ 47 extern int nclistelemremove(NClist* l, void* elem); 48 49 /* remove duplicates */ 50 extern int nclistunique(NClist*); 51 52 /* Create a clone of a list */ 53 extern NClist* nclistclone(NClist*); 54 55 extern void* nclistextract(NClist*); 56 57 /* Following are always "in-lined"*/ 58 #define nclistclear(l) nclistsetlength((l),0) 59 #define nclistextend(l,len) nclistsetalloc((l),(len)+(l->alloc)) 60 #define nclistcontents(l) ((l)==NULL?NULL:(l)->content) 61 #define nclistlength(l) ((l)==NULL?0:(l)->length) 62 63 #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__) 64 } 65 #endif 66 67 #endif /*NCLIST_H*/ 68