zf_list.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. *****************************************************************************
  3. * @file zf_list.h
  4. * @author Zorb
  5. * @version V1.0.0
  6. * @date 2018-06-28
  7. * @brief 简单列表的头文件
  8. *****************************************************************************
  9. * @history
  10. *
  11. * 1. Date:2018-06-28
  12. * Author:Zorb
  13. * Modification:建立文件
  14. *
  15. *****************************************************************************
  16. */
  17. #ifndef __ZF_LIST_H__
  18. #define __ZF_LIST_H__
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include "stdbool.h"
  23. #include "stdint.h"
  24. /* 列表节点结构 */
  25. typedef struct _ListNode
  26. {
  27. bool IsExternData; /* 是否外部数据,是则销毁时不释放 */
  28. uint8_t *pData; /* 指向数据的指针 */
  29. uint32_t Size; /* 数据的大小 */
  30. struct _ListNode *Next; /* 指向下一个节点 */
  31. } ListNode;
  32. /* 列表结构 */
  33. typedef struct _List
  34. {
  35. ListNode *pRootNode; /* 指向根节点数据 */
  36. uint32_t Count; /* 节点个数 */
  37. /* 在尾端增加节点 */
  38. bool (*Add)(struct _List * const pList, ListNode *pNode);
  39. /* 删除节点(释放空间) */
  40. bool (*Delete)(struct _List * const pList, ListNode *pNode);
  41. /* 移除节点(不释放空间) */
  42. bool (*Remove)(struct _List * const pList, ListNode *pNode);
  43. /* 返回指定索引处的节点的指针 */
  44. bool (*GetElementAt)(struct _List * const pList, uint32_t index,
  45. ListNode **ppNode);
  46. /* 返回数据区指向data的节点的指针 */
  47. bool (*GetElementByData)(struct _List * const pList, void *pdata,
  48. ListNode **ppNode);
  49. /* 返回指定索引处的节点的数据缓冲区的指针 */
  50. void *(*GetElementDataAt)(struct _List * const pList, uint32_t index);
  51. /* 返回节点的索引 */
  52. bool (*GetElementIndex)(struct _List * const pList, ListNode *pNode,
  53. uint32_t *pIndex);
  54. /* 在指定索引处增加节点 */
  55. bool (*AddElementAt)(struct _List * const pList, uint32_t index,
  56. ListNode *pNode);
  57. /* 在指定索引处删除节点(释放空间) */
  58. bool (*DeleteElementAt)(struct _List * const pList, uint32_t index);
  59. /* 在指定索引处移除节点(不释放空间) */
  60. bool (*RemoveElementAt)(struct _List * const pList, uint32_t index);
  61. /* 清空列表(释放空间) */
  62. bool (*Clear)(struct _List * const pList);
  63. /* 释放列表(释放空间) */
  64. bool (*Dispose)(struct _List * const pList);
  65. } List;
  66. /* 创建列表(内部分配空间) */
  67. bool List_create(List **ppList);
  68. /* 在尾端增加节点 */
  69. bool List_add(List * const pList, ListNode *pNode);
  70. /* 删除节点(内部释放空间) */
  71. bool List_delete(List * const pList, ListNode *pNode);
  72. /* 移除节点(内部不释放空间) */
  73. bool List_remove(List * const pList, ListNode *pNode);
  74. /* 返回指定索引处的节点的指针 */
  75. bool List_getElementAt(List * const pList, uint32_t index,
  76. ListNode **ppNode);
  77. /* 返回数据区指向data的节点的指针 */
  78. bool List_getElementByData(List * const pList, void *pdata,
  79. ListNode **ppNode);
  80. /* 返回指定索引处的节点的数据缓冲区的指针 */
  81. void *List_getElementDataAt(List * const pList, uint32_t index);
  82. /* 返回节点的索引 */
  83. bool List_getElementIndex(List * const pList, ListNode *pNode,
  84. uint32_t *pIndex);
  85. /* 在指定索引处增加节点 */
  86. bool List_addElementAt(List * const pList, uint32_t index,
  87. ListNode *pNode);
  88. /* 在指定索引处删除节点(内部释放空间) */
  89. bool List_deleteElementAt(List * const pList, uint32_t index);
  90. /* 在指定索引处移除节点(不释放空间) */
  91. bool List_removeElementAt(List * const pList, uint32_t index);
  92. /* 清空列表(内部释放空间) */
  93. bool List_clear(List * const pList);
  94. /* 释放列表(内部释放空间) */
  95. bool List_dispose(List * const pList);
  96. /* 创建节点(内部分配空间,size=0表示使用外部数据) */
  97. bool List_mallocNode(ListNode **ppNode, void **ppData, uint32_t size);
  98. /* 释放节点(不释放外部创建的数据) */
  99. bool List_freeNode(ListNode *pNode);
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* __ZF_LIST_H__ */
  104. /******************************** END OF FILE ********************************/