LinkedList.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*******************************************************************************
  2. * Copyright (c) 2009, 2013 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * http://www.eclipse.org/legal/epl-v10.html
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial API and implementation and/or initial documentation
  15. * Ian Craggs - updates for the async client
  16. * Ian Craggs - change size types from int to size_t
  17. *******************************************************************************/
  18. #if !defined(LINKEDLIST_H)
  19. #define LINKEDLIST_H
  20. #include <stdlib.h> /* for size_t definition */
  21. /*BE
  22. defm defList(T)
  23. def T concat Item
  24. {
  25. at 4
  26. n32 ptr T concat Item suppress "next"
  27. at 0
  28. n32 ptr T concat Item suppress "prev"
  29. at 8
  30. n32 ptr T id2str(T)
  31. }
  32. def T concat List
  33. {
  34. n32 ptr T concat Item suppress "first"
  35. n32 ptr T concat Item suppress "last"
  36. n32 ptr T concat Item suppress "current"
  37. n32 dec "count"
  38. n32 suppress "size"
  39. }
  40. endm
  41. defList(INT)
  42. defList(STRING)
  43. defList(TMP)
  44. BE*/
  45. /**
  46. * Structure to hold all data for one list element
  47. */
  48. typedef struct ListElementStruct
  49. {
  50. struct ListElementStruct *prev, /**< pointer to previous list element */
  51. *next; /**< pointer to next list element */
  52. void* content; /**< pointer to element content */
  53. } ListElement;
  54. /**
  55. * Structure to hold all data for one list
  56. */
  57. typedef struct
  58. {
  59. ListElement *first, /**< first element in the list */
  60. *last, /**< last element in the list */
  61. *current; /**< current element in the list, for iteration */
  62. int count; /**< no of items */
  63. size_t size; /**< heap storage used */
  64. } List;
  65. void ListZero(List*);
  66. List* ListInitialize(void);
  67. void ListAppend(List* aList, void* content, size_t size);
  68. void ListAppendNoMalloc(List* aList, void* content, ListElement* newel, size_t size);
  69. void ListInsert(List* aList, void* content, size_t size, ListElement* index);
  70. int ListRemove(List* aList, void* content);
  71. int ListRemoveItem(List* aList, void* content, int(*callback)(void*, void*));
  72. void* ListDetachHead(List* aList);
  73. int ListRemoveHead(List* aList);
  74. void* ListPopTail(List* aList);
  75. int ListDetach(List* aList, void* content);
  76. int ListDetachItem(List* aList, void* content, int(*callback)(void*, void*));
  77. void ListFree(List* aList);
  78. void ListEmpty(List* aList);
  79. void ListFreeNoContent(List* aList);
  80. ListElement* ListNextElement(List* aList, ListElement** pos);
  81. ListElement* ListPrevElement(List* aList, ListElement** pos);
  82. ListElement* ListFind(List* aList, void* content);
  83. ListElement* ListFindItem(List* aList, void* content, int(*callback)(void*, void*));
  84. int intcompare(void* a, void* b);
  85. int stringcompare(void* a, void* b);
  86. #endif