ua_list.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef UA_LIST_H_
  2. #define UA_LIST_H_
  3. #include "opcua.h"
  4. #include <stddef.h> /* Needed for sys/queue.h */
  5. #include <sys/queue.h>
  6. /**********************/
  7. /* Singly Linked List */
  8. /**********************/
  9. #define UA_SLIST_HEAD(name, type) SLIST_HEAD(name, type)
  10. #define UA_SLIST_HEAD_INITIALIZER(head) SLIST_HEAD_INITILIZER(head)
  11. #define UA_SLIST_ENTRY(type) SLIST_ENTRY(type)
  12. #define UA_SLIST_INIT(head) SLIST_INIT(head)
  13. #define UA_SLIST_INSERT_AFTER(slistelm, elm, field) SLIST_INSERT_AFTER(slistelm, elm, field)
  14. #define UA_SLIST_INSERT_HEAD(head, elm, field) SLIST_INSERT_HEAD(head, elm, field)
  15. #define UA_SLIST_REMOVE_HEAD(head, field) SLIST_REMOVE_HEAD(head, field)
  16. #define UA_SLIST_REMOVE(head, elm, type, field) SLIST_REMOVE(head, elm, type, field)
  17. #define UA_SLIST_FOREACH(var, head, field) SLIST_FOREACH(var, head, field)
  18. #define UA_SLIST_EMPTY(head) SLIST_EMPTY(head)
  19. #define UA_SLIST_FIRST(head) SLIST_FIRST(head)
  20. #define UA_SLIST_NEXT(elm, field) SLIST_NEXT(elm, field)
  21. /**********************/
  22. /* Doubly Linked List */
  23. /**********************/
  24. typedef void (*UA_list_PayloadVisitor)(void* payload);
  25. typedef struct UA_list_Element {
  26. struct UA_list_List* father;
  27. void *payload;
  28. struct UA_list_Element* next;
  29. struct UA_list_Element* prev;
  30. }UA_list_Element;
  31. typedef struct UA_list_List {
  32. struct UA_list_Element* first;
  33. struct UA_list_Element* last;
  34. UA_Int32 size;
  35. }UA_list_List;
  36. typedef void (*UA_list_ElementVisitor)(UA_list_Element* payload);
  37. //typedef Boolean (*UA_list_PayloadMatcher)(void* payload);
  38. typedef _Bool (*UA_list_PayloadMatcher)(void* payload);
  39. typedef _Bool (*UA_list_PayloadComparer)(void* payload, void* otherPayload);
  40. void UA_list_defaultFreer(void* payload);
  41. UA_Int32 UA_list_initElement(UA_list_Element* element);
  42. UA_Int32 UA_list_init(UA_list_List* list);
  43. UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element);
  44. UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload);
  45. UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element);
  46. UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload);
  47. UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor);
  48. UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor);
  49. UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisitor visitor);
  50. UA_Int32 UA_list_destroy(UA_list_List* list, UA_list_PayloadVisitor visitor);
  51. UA_Int32 UA_list_iterateElement(UA_list_List* const list, UA_list_ElementVisitor visitor);
  52. UA_Int32 UA_list_iteratePayload(UA_list_List* const list, UA_list_PayloadVisitor visitor);
  53. UA_list_Element* UA_list_find(UA_list_List* const list, UA_list_PayloadMatcher matcher);
  54. UA_list_Element* UA_list_search(UA_list_List* const list, UA_list_PayloadComparer compare, void* payload);
  55. UA_list_Element* UA_list_getFirst(UA_list_List* const list);
  56. UA_list_Element* UA_list_getLast(UA_list_List* const list);
  57. #endif /* UA_LIST_H_ */