pvl.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*======================================================================
  2. FILE: pvl.h
  3. CREATOR: eric November, 1995
  4. (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
  5. http://www.softwarestudio.org
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of either:
  8. The LGPL as published by the Free Software Foundation, version
  9. 2.1, available at: http://www.gnu.org/licenses/lgpl-2.1.html
  10. Or:
  11. The Mozilla Public License Version 1.0. You may obtain a copy of
  12. the License at http://www.mozilla.org/MPL/
  13. ======================================================================*/
  14. #ifndef ICAL_PVL_H
  15. #define ICAL_PVL_H
  16. #include "libical_ical_export.h"
  17. typedef struct pvl_list_t *pvl_list;
  18. typedef struct pvl_elem_t *pvl_elem;
  19. /**
  20. * This type is private. Always use pvl_elem instead. The struct would
  21. * not even appear in this header except to make code in the USE_MACROS
  22. * blocks work
  23. */
  24. typedef struct pvl_elem_t
  25. {
  26. int MAGIC; /**< Magic Identifier */
  27. void *d; /**< Pointer to data user is storing */
  28. struct pvl_elem_t *next; /**< Next element */
  29. struct pvl_elem_t *prior; /**< Prior element */
  30. } pvl_elem_t;
  31. /* Create new lists or elements */
  32. LIBICAL_ICAL_EXPORT pvl_elem pvl_new_element(void *d, pvl_elem next, pvl_elem prior);
  33. LIBICAL_ICAL_EXPORT pvl_list pvl_newlist(void);
  34. LIBICAL_ICAL_EXPORT void pvl_free(pvl_list);
  35. /* Add, remove, or get the head of the list */
  36. LIBICAL_ICAL_EXPORT void pvl_unshift(pvl_list l, void *d);
  37. LIBICAL_ICAL_EXPORT void *pvl_shift(pvl_list l);
  38. LIBICAL_ICAL_EXPORT pvl_elem pvl_head(pvl_list);
  39. /* Add, remove or get the tail of the list */
  40. LIBICAL_ICAL_EXPORT void pvl_push(pvl_list l, void *d);
  41. LIBICAL_ICAL_EXPORT void *pvl_pop(pvl_list l);
  42. LIBICAL_ICAL_EXPORT pvl_elem pvl_tail(pvl_list);
  43. /* Insert elements in random places */
  44. typedef int (*pvl_comparef) (void *a, void *b); /* a, b are of the data type */
  45. LIBICAL_ICAL_EXPORT void pvl_insert_ordered(pvl_list l, pvl_comparef f, void *d);
  46. LIBICAL_ICAL_EXPORT void pvl_insert_after(pvl_list l, pvl_elem e, void *d);
  47. LIBICAL_ICAL_EXPORT void pvl_insert_before(pvl_list l, pvl_elem e, void *d);
  48. /* Remove an element, or clear the entire list */
  49. LIBICAL_ICAL_EXPORT void *pvl_remove(pvl_list, pvl_elem); /* Remove element, return data */
  50. LIBICAL_ICAL_EXPORT void pvl_clear(pvl_list); /* Remove all elements, de-allocate all data */
  51. LIBICAL_ICAL_EXPORT int pvl_count(pvl_list);
  52. /* Navagate the list */
  53. LIBICAL_ICAL_EXPORT pvl_elem pvl_next(pvl_elem e);
  54. LIBICAL_ICAL_EXPORT pvl_elem pvl_prior(pvl_elem e);
  55. /* get the data in the list */
  56. #if !defined(PVL_USE_MACROS)
  57. LIBICAL_ICAL_EXPORT void *pvl_data(pvl_elem);
  58. #else
  59. #define pvl_data(x) x==0 ? 0 : ((struct pvl_elem_t *)x)->d;
  60. #endif
  61. /* Find an element for which a function returns true */
  62. typedef int (*pvl_findf) (void *a, void *b); /*a is list elem, b is other data */
  63. LIBICAL_ICAL_EXPORT pvl_elem pvl_find(pvl_list l, pvl_findf f, void *v);
  64. LIBICAL_ICAL_EXPORT pvl_elem pvl_find_next(pvl_list l, pvl_findf f, void *v);
  65. /**
  66. * Pass each element in the list to a function
  67. * a is list elem, b is other data
  68. */
  69. typedef void (*pvl_applyf) (void *a, void *b);
  70. LIBICAL_ICAL_EXPORT void pvl_apply(pvl_list l, pvl_applyf f, void *v);
  71. #endif /* ICAL_PVL_H */