list.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef __LIST_Hx__
  2. #define __LIST_Hx__
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef void* handle_t;
  10. enum {
  11. LIST_FULL_FIFO=0,
  12. LIST_FULL_FILO,
  13. };
  14. enum {
  15. LIST_SORT_ASCEND=0,
  16. LIST_SORT_DESCEND,
  17. LIST_SORT_MAX
  18. };
  19. enum {
  20. LIST_ACT_NONE=0,
  21. LIST_ACT_STOP,
  22. LIST_ACT_REMOVE,
  23. LIST_ACT_DELETE,
  24. };
  25. typedef struct {
  26. int tp; //type
  27. void *buf;
  28. int dlen; //data len
  29. int blen; //buf len
  30. }node_t;
  31. typedef struct list_node {
  32. node_t data;
  33. struct list_node *prev;
  34. struct list_node *next;
  35. }list_node_t;
  36. typedef struct {
  37. int log; //0:disable 1: enable
  38. int mode;
  39. int max; //the max count
  40. }list_cfg_t;
  41. //该函数返回负值是表示结束,将退出迭代循环
  42. //该函数返回值>=0将继续迭代至结束
  43. typedef int (*list_callback_t)(handle_t l, node_t *node, node_t *xd, void *arg, int *act);
  44. handle_t list_init(list_cfg_t *cfg);
  45. int list_free(handle_t l);
  46. int list_get_node(handle_t l, list_node_t **lnode, int index);
  47. int list_set_node(handle_t l, list_node_t *lnode, int index);
  48. int list_take_node(handle_t l, list_node_t **lnode, int index);
  49. int list_back_node(handle_t l, list_node_t *lnode);
  50. int list_discard_node(handle_t l, list_node_t *lnode);
  51. int list_insert(handle_t l, node_t *node, int index);
  52. int list_insert_node(handle_t l, list_node_t *lnode, int index);
  53. int list_append(handle_t l, int tp, void *data, int len);
  54. int list_append_node(handle_t l, list_node_t *lnode);
  55. int list_infront(handle_t l, int tp, void *data, int len);
  56. int list_infront_node(handle_t l, list_node_t *lnode);
  57. int list_remove(handle_t l, int index);
  58. int list_delete(handle_t l, int index);
  59. int list_sort(handle_t l, int order);
  60. int list_size(handle_t l);
  61. int list_clear(handle_t l);
  62. int list_iterator(handle_t l, node_t *node, list_callback_t callback, void *arg);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif