list.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef TINC_LIST_H
  2. #define TINC_LIST_H
  3. /*
  4. list.h -- header file for list.c
  5. Copyright (C) 2000-2005 Ivo Timmermans
  6. 2000-2006 Guus Sliepen <guus@tinc-vpn.org>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc.,
  17. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  19. typedef struct list_node_t {
  20. struct list_node_t *prev;
  21. struct list_node_t *next;
  22. /* Payload */
  23. void *data;
  24. } list_node_t;
  25. typedef void (*list_action_t)(const void *);
  26. typedef void (*list_action_node_t)(const list_node_t *);
  27. typedef struct list_t {
  28. list_node_t *head;
  29. list_node_t *tail;
  30. int count;
  31. /* Callbacks */
  32. list_action_t delete;
  33. } list_t;
  34. /* (De)constructors */
  35. extern list_t *list_alloc(list_action_t) __attribute__((__malloc__));
  36. extern void list_free(list_t *list);
  37. extern list_node_t *list_alloc_node(void);
  38. extern void list_free_node(list_t *list, list_node_t *node);
  39. /* Insertion and deletion */
  40. extern list_node_t *list_insert_head(list_t *list, void *data);
  41. extern list_node_t *list_insert_tail(list_t *list, void *data);
  42. extern void list_unlink_node(list_t *list, list_node_t *node);
  43. extern void list_delete_node(list_t *list, list_node_t *node);
  44. extern void list_delete_head(list_t *list);
  45. extern void list_delete_tail(list_t *list);
  46. /* Head/tail lookup */
  47. extern void *list_get_head(list_t *list);
  48. extern void *list_get_tail(list_t *list);
  49. /* Fast list deletion */
  50. extern void list_delete_list(list_t *list);
  51. /* Traversing */
  52. extern void list_foreach(list_t *list, list_action_t action);
  53. extern void list_foreach_node(list_t *list, list_action_node_t action);
  54. #endif