lv_ll.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * @file lv_ll.c
  3. * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module.
  4. */
  5. #ifndef LV_LL_H
  6. #define LV_LL_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*********************
  11. * INCLUDES
  12. *********************/
  13. #include "lv_mem.h"
  14. #include <stdint.h>
  15. #include <stddef.h>
  16. /*********************
  17. * DEFINES
  18. *********************/
  19. /**********************
  20. * TYPEDEFS
  21. **********************/
  22. /*Dummy type to make handling easier*/
  23. typedef uint8_t lv_ll_node_t;
  24. /*Description of a linked list*/
  25. typedef struct
  26. {
  27. uint32_t n_size;
  28. lv_ll_node_t* head;
  29. lv_ll_node_t* tail;
  30. }lv_ll_t;
  31. /**********************
  32. * GLOBAL PROTOTYPES
  33. **********************/
  34. /**
  35. * Initialize linked list
  36. * @param ll_dsc pointer to ll_dsc variable
  37. * @param node_size the size of 1 node in bytes
  38. */
  39. void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size);
  40. /**
  41. * Add a new head to a linked list
  42. * @param ll_p pointer to linked list
  43. * @return pointer to the new head
  44. */
  45. void * lv_ll_ins_head(lv_ll_t * ll_p);
  46. /**
  47. * Insert a new node in front of the n_act node
  48. * @param ll_p pointer to linked list
  49. * @param n_act pointer a node
  50. * @return pointer to the new head
  51. */
  52. void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act);
  53. /**
  54. * Add a new tail to a linked list
  55. * @param ll_p pointer to linked list
  56. * @return pointer to the new tail
  57. */
  58. void * lv_ll_ins_tail(lv_ll_t * ll_p);
  59. /**
  60. * Remove the node 'node_p' from 'll_p' linked list.
  61. * It Dose not free the the memory of node.
  62. * @param ll_p pointer to the linked list of 'node_p'
  63. * @param node_p pointer to node in 'll_p' linked list
  64. */
  65. void lv_ll_rem(lv_ll_t * ll_p, void * node_p);
  66. /**
  67. * Remove and free all elements from a linked list. The list remain valid but become empty.
  68. * @param ll_p pointer to linked list
  69. */
  70. void lv_ll_clear(lv_ll_t * ll_p);
  71. /**
  72. * Move a node to a new linked list
  73. * @param ll_ori_p pointer to the original (old) linked list
  74. * @param ll_new_p pointer to the new linked list
  75. * @param node pointer to a node
  76. */
  77. void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node);
  78. /**
  79. * Return with head node of the linked list
  80. * @param ll_p pointer to linked list
  81. * @return pointer to the head of 'll_p'
  82. */
  83. void * lv_ll_get_head(lv_ll_t * ll_p);
  84. /**
  85. * Return with tail node of the linked list
  86. * @param ll_p pointer to linked list
  87. * @return pointer to the head of 'll_p'
  88. */
  89. void * lv_ll_get_tail(lv_ll_t * ll_p);
  90. /**
  91. * Return with the pointer of the next node after 'n_act'
  92. * @param ll_p pointer to linked list
  93. * @param n_act pointer a node
  94. * @return pointer to the next node
  95. */
  96. void * lv_ll_get_next(lv_ll_t * ll_p, void * n_act);
  97. /**
  98. * Return with the pointer of the previous node after 'n_act'
  99. * @param ll_p pointer to linked list
  100. * @param n_act pointer a node
  101. * @return pointer to the previous node
  102. */
  103. void * lv_ll_get_prev(lv_ll_t * ll_p, void * n_act);
  104. /**
  105. * Move a nodw before an other node in the same linked list
  106. * @param ll_p pointer to a linked list
  107. * @param n_act pointer to node to move
  108. * @param n_after pointer to a node which should be after `n_act`
  109. */
  110. void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after);
  111. /**********************
  112. * MACROS
  113. **********************/
  114. #define LL_READ(list, i) for(i = lv_ll_get_head(&list); i != NULL; i = lv_ll_get_next(&list, i))
  115. #define LL_READ_BACK(list, i) for(i = lv_ll_get_tail(&list); i != NULL; i = lv_ll_get_prev(&list, i))
  116. #ifdef __cplusplus
  117. } /* extern "C" */
  118. #endif
  119. #endif