nclist.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /* Define the type of the elements in the list*/
  6. #if defined(_CPLUSPLUS_) || defined(__CPLUSPLUS__)
  7. #define EXTERNC extern "C"
  8. #else
  9. #define EXTERNC extern
  10. #endif
  11. typedef unsigned long ncelem;
  12. EXTERNC int nclistnull(ncelem);
  13. typedef struct NClist {
  14. unsigned int alloc;
  15. unsigned int length;
  16. ncelem* content;
  17. } NClist;
  18. EXTERNC NClist* nclistnew(void);
  19. EXTERNC int nclistfree(NClist*);
  20. EXTERNC int nclistsetalloc(NClist*,unsigned int);
  21. EXTERNC int nclistsetlength(NClist*,unsigned int);
  22. /* Set the ith element */
  23. EXTERNC int nclistset(NClist*,unsigned int,ncelem);
  24. /* Get value at position i */
  25. EXTERNC ncelem nclistget(NClist*,unsigned int);/* Return the ith element of l */
  26. /* Insert at position i; will push up elements i..|seq|. */
  27. EXTERNC int nclistinsert(NClist*,unsigned int,ncelem);
  28. /* Remove element at position i; will move higher elements down */
  29. EXTERNC ncelem nclistremove(NClist* l, unsigned int i);
  30. /* Tail operations */
  31. EXTERNC int nclistpush(NClist*,ncelem); /* Add at Tail */
  32. EXTERNC ncelem nclistpop(NClist*);
  33. EXTERNC ncelem nclisttop(NClist*);
  34. /* Duplicate and return the content (null terminate) */
  35. EXTERNC ncelem* nclistdup(NClist*);
  36. /* Look for value match */
  37. EXTERNC int nclistcontains(NClist*, ncelem);
  38. /* Remove element by value; only removes first encountered */
  39. EXTERNC int nclistelemremove(NClist* l, ncelem elem);
  40. /* remove duplicates */
  41. EXTERNC int nclistunique(NClist*);
  42. /* Create a clone of a list */
  43. EXTERNC NClist* nclistclone(NClist*);
  44. /* Following are always "in-lined"*/
  45. #define nclistclear(l) nclistsetlength((l),0U)
  46. #define nclistextend(l,len) nclistsetalloc((l),(len)+(l->alloc))
  47. #define nclistcontents(l) ((l)->content)
  48. #define nclistlength(l) ((l)?(l)->length:0U)
  49. #endif /*NCLIST_H*/