oclist.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. /* 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 ocelem;
  12. EXTERNC int oclistnull(ocelem);
  13. typedef struct OClist {
  14. unsigned int alloc;
  15. unsigned int length;
  16. ocelem* content;
  17. } OClist;
  18. EXTERNC OClist* oclistnewn(int);
  19. EXTERNC int oclistfree(OClist*);
  20. EXTERNC int oclistsetalloc(OClist*,unsigned int);
  21. EXTERNC int oclistsetlength(OClist*,unsigned int);
  22. /* Set the ith element */
  23. EXTERNC int oclistset(OClist*,unsigned int,ocelem);
  24. /* Get value at position i */
  25. EXTERNC ocelem oclistget(OClist*,unsigned int);/* Return the ith element of l */
  26. /* Insert at position i; will push up elements i..|seq|. */
  27. EXTERNC int oclistinsert(OClist*,unsigned int,ocelem);
  28. /* Remove element at position i; will move higher elements down */
  29. EXTERNC ocelem oclistremove(OClist* l, unsigned int i);
  30. /* Tail operations */
  31. EXTERNC int oclistpush(OClist*,ocelem); /* Add at Tail */
  32. EXTERNC ocelem oclistpop(OClist*);
  33. EXTERNC ocelem oclisttop(OClist*);
  34. /* Duplicate and return the content (null terminate) */
  35. EXTERNC ocelem* oclistdup(OClist*);
  36. /* Look for value match */
  37. EXTERNC int oclistcontains(OClist*, ocelem);
  38. /* Following are always "in-lined"*/
  39. #define oclistnew() oclistnewn(0)
  40. #define oclistclear(l) oclistsetlength((l),0U)
  41. #define oclistextend(l,len) oclistsetalloc((l),(len)+(l->alloc))
  42. #define oclistcontents(l) ((l)->content)
  43. #define oclistlength(l) ((l)?(l)->length:0U)
  44. #endif /*OCLIST_H*/