autotree.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. filesummary.CH: 一个由引用计数管理的智能树,包含拓展的C语法来快速创建和操作元素
  3. filesummary.EN: Representation an reference count managed tree, included extended C gramma to quick create and access it's node
  4. CH: 表示由AutoTree内存区管理的一棵树,或一个节点。可以是键值对、数组、字符串、整形、浮点型,其存储在AutoTree内存区并由引用计数管理。
  5. EN: Describing an AutoTree managed tree, or node. The value of it can be a key-value set, or an array, number and string, they storage in AutoTree memory zone and their life-cycle managed by reference count.
  6. */
  7. typedef builtin AutoTree;
  8. /*
  9. CH: 表示树节点的类型
  10. EN: Describing Tree Type
  11. */
  12. typedef builtin TreeType;
  13. /*
  14. CH: 表示一个用于遍历树的迭代器
  15. EN: Describing Tree Iterator
  16. */
  17. typedef builtin Iterator;
  18. /*
  19. CH: 将一个JSON字符串转换成AutoTree树
  20. EN: Transfer a JSON string to an AutoTree object
  21. json.CH: 一个JSON字符串,此函数仅读取给定的字符串并创建新的内存来存储树
  22. json.EN: A JSON string, this function only read specified string and allocate the tree in AutoTree memory zone
  23. */
  24. AutoTree json_tree(char* json);
  25. /*
  26. CH: 将一棵树转换为JSON,写入writeTo
  27. EN: Transfer a Tree to JSON
  28. tree.CH: 待转换的树
  29. tree.EN: Tree to transfer
  30. writeTo.CH: 写入JSON字符串的地址
  31. writeTo.EN: JSON string write to address
  32. writeToSize.CH: JSON字符串最大长度
  33. writeToSize.EN: Maxium length of writeTo
  34. */
  35. size_t tree_json(AutoTree tree, char* writeTo, size_t writeToSize);
  36. /*
  37. CH: 为节点降低1个引用计数
  38. EN: Release tree node once
  39. tree.CH: 操作对象
  40. tree.EN: Target tree
  41. */
  42. void tree_release(AutoTree tree);
  43. /*
  44. CH: 为节点增加1个引用计数
  45. EN: Retain tree node once
  46. tree.CH: 操作对象
  47. tree.EN: Target tree
  48. */
  49. void tree_retain(AutoTree tree);
  50. /*
  51. CH: 获取节点引用计数
  52. EN: Get the reference count of node
  53. tree.CH: 操作对象
  54. tree.EN: Target tree
  55. */
  56. int tree_refcnt(AutoTree tree);
  57. /*
  58. CH: 获取树的path处元素
  59. EN: Get the specified path element of the tree
  60. tree.CH: 操作对象
  61. tree.EN: Target tree
  62. path.CH: 路径字符串
  63. path.EN: Specified path
  64. */
  65. AutoTree tree_path(AutoTree tree, char* path);
  66. /*
  67. CH: 获取一棵空树,空树在程序中唯一,引用计数无穷大
  68. EN: Get an unique empty tree, it has infinite reference count
  69. */
  70. AutoTree tree_null();
  71. /*
  72. CH: 深拷贝一棵树
  73. EN: Deep copy a tree
  74. fromTree.CH: 被拷贝的树
  75. fromTree.EN: The tree to copy
  76. */
  77. AutoTree tree_clone(AutoTree fromTree);
  78. /*
  79. CH: 为一个KV节点或数组节点创建迭代器以便遍历
  80. EN: Create iterator for a kv node or array node to foreach
  81. tree.CH: 要创建迭代器的tree节点
  82. tree.EN: The tree to create iterator
  83. */
  84. Iterator tree_iterator(AutoTree tree);
  85. /*
  86. CH: 迭代器到下一项
  87. EN: Move iterator to next
  88. iterator.CH: 迭代器
  89. iterator.EN: The iterator
  90. pathNameWriteTo.CH: 要写入下一项名称的字符串地址
  91. pathNameWriteTo.EN: The string address to write next element name
  92. writeToSize.CH: 最大写入长度
  93. writeToSize.EN: Maxium length of pathNameWriteTo
  94. */
  95. int iterator_next(Iterator &iterator, char *pathNameWriteTo, int writeToSize);
  96. /*
  97. CH: 销毁迭代器
  98. EN: Destroy an iterator
  99. iterator.CH: 要销毁的迭代器
  100. iterator.EN: The iterator to be destroy
  101. */
  102. void iterator_destroy(Iterator &iterator);
  103. /*
  104. CH: 获取节点的类型
  105. EN: Get the type of the tree node
  106. tree.CH: 节点
  107. tree.EN: tree node
  108. */
  109. TreeType tree_typeof(AutoTree tree);
  110. /*
  111. CH: 如果节点是数组,获取它的长度
  112. EN: If the node is an array, get the length of it
  113. tree.CH: 节点
  114. tree.EN: tree node
  115. */
  116. size_t tree_arraylen(AutoTree tree);
  117. /*
  118. CH: 32或64位整数节点类型
  119. EN: 32Bit or 64Bit integer node type
  120. */
  121. TreeType tree_int;
  122. /*
  123. CH: 字符串节点类型
  124. EN: String node type
  125. */
  126. TreeType tree_str;
  127. /*
  128. CH: 空节点类型
  129. EN: Null node type
  130. */
  131. TreeType tree_empty;
  132. /*
  133. CH: 键值对节点类型
  134. EN: Key-value map node type
  135. */
  136. TreeType tree_kv;
  137. /*
  138. CH: 数组节点类型
  139. EN: Array node type
  140. */
  141. TreeType tree_array;
  142. /*
  143. CH: 32位或64位浮点数节点类型
  144. EN: 32Bit or 64Bit float node type
  145. */
  146. TreeType tree_double;