You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
6.4 KiB

4 years ago
  1. /*
  2. * Summary: Chained hash tables
  3. * Description: This module implements the hash table support used in
  4. * various places in the library.
  5. *
  6. * Copy: See Copyright for the status of this software.
  7. *
  8. * Author: Bjorn Reese <bjorn.reese@systematic.dk>
  9. */
  10. #ifndef __XML_HASH_H__
  11. #define __XML_HASH_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /*
  16. * The hash table.
  17. */
  18. typedef struct _xmlHashTable xmlHashTable;
  19. typedef xmlHashTable *xmlHashTablePtr;
  20. #ifdef __cplusplus
  21. }
  22. #endif
  23. #include <libxml/xmlversion.h>
  24. #include <libxml/parser.h>
  25. #include <libxml/dict.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /*
  30. * Recent version of gcc produce a warning when a function pointer is assigned
  31. * to an object pointer, or vice versa. The following macro is a dirty hack
  32. * to allow suppression of the warning. If your architecture has function
  33. * pointers which are a different size than a void pointer, there may be some
  34. * serious trouble within the library.
  35. */
  36. /**
  37. * XML_CAST_FPTR:
  38. * @fptr: pointer to a function
  39. *
  40. * Macro to do a casting from an object pointer to a
  41. * function pointer without encountering a warning from
  42. * gcc
  43. *
  44. * #define XML_CAST_FPTR(fptr) (*(void **)(&fptr))
  45. * This macro violated ISO C aliasing rules (gcc4 on s390 broke)
  46. * so it is disabled now
  47. */
  48. #define XML_CAST_FPTR(fptr) fptr
  49. /*
  50. * function types:
  51. */
  52. /**
  53. * xmlHashDeallocator:
  54. * @payload: the data in the hash
  55. * @name: the name associated
  56. *
  57. * Callback to free data from a hash.
  58. */
  59. typedef void (*xmlHashDeallocator)(void *payload, const xmlChar *name);
  60. /**
  61. * xmlHashCopier:
  62. * @payload: the data in the hash
  63. * @name: the name associated
  64. *
  65. * Callback to copy data from a hash.
  66. *
  67. * Returns a copy of the data or NULL in case of error.
  68. */
  69. typedef void *(*xmlHashCopier)(void *payload, const xmlChar *name);
  70. /**
  71. * xmlHashScanner:
  72. * @payload: the data in the hash
  73. * @data: extra scannner data
  74. * @name: the name associated
  75. *
  76. * Callback when scanning data in a hash with the simple scanner.
  77. */
  78. typedef void (*xmlHashScanner)(void *payload, void *data, const xmlChar *name);
  79. /**
  80. * xmlHashScannerFull:
  81. * @payload: the data in the hash
  82. * @data: extra scannner data
  83. * @name: the name associated
  84. * @name2: the second name associated
  85. * @name3: the third name associated
  86. *
  87. * Callback when scanning data in a hash with the full scanner.
  88. */
  89. typedef void (*xmlHashScannerFull)(void *payload, void *data,
  90. const xmlChar *name, const xmlChar *name2,
  91. const xmlChar *name3);
  92. /*
  93. * Constructor and destructor.
  94. */
  95. XMLPUBFUN xmlHashTablePtr XMLCALL
  96. xmlHashCreate (int size);
  97. XMLPUBFUN xmlHashTablePtr XMLCALL
  98. xmlHashCreateDict(int size,
  99. xmlDictPtr dict);
  100. XMLPUBFUN void XMLCALL
  101. xmlHashFree (xmlHashTablePtr table,
  102. xmlHashDeallocator f);
  103. XMLPUBFUN void XMLCALL
  104. xmlHashDefaultDeallocator(void *entry,
  105. const xmlChar *name);
  106. /*
  107. * Add a new entry to the hash table.
  108. */
  109. XMLPUBFUN int XMLCALL
  110. xmlHashAddEntry (xmlHashTablePtr table,
  111. const xmlChar *name,
  112. void *userdata);
  113. XMLPUBFUN int XMLCALL
  114. xmlHashUpdateEntry(xmlHashTablePtr table,
  115. const xmlChar *name,
  116. void *userdata,
  117. xmlHashDeallocator f);
  118. XMLPUBFUN int XMLCALL
  119. xmlHashAddEntry2(xmlHashTablePtr table,
  120. const xmlChar *name,
  121. const xmlChar *name2,
  122. void *userdata);
  123. XMLPUBFUN int XMLCALL
  124. xmlHashUpdateEntry2(xmlHashTablePtr table,
  125. const xmlChar *name,
  126. const xmlChar *name2,
  127. void *userdata,
  128. xmlHashDeallocator f);
  129. XMLPUBFUN int XMLCALL
  130. xmlHashAddEntry3(xmlHashTablePtr table,
  131. const xmlChar *name,
  132. const xmlChar *name2,
  133. const xmlChar *name3,
  134. void *userdata);
  135. XMLPUBFUN int XMLCALL
  136. xmlHashUpdateEntry3(xmlHashTablePtr table,
  137. const xmlChar *name,
  138. const xmlChar *name2,
  139. const xmlChar *name3,
  140. void *userdata,
  141. xmlHashDeallocator f);
  142. /*
  143. * Remove an entry from the hash table.
  144. */
  145. XMLPUBFUN int XMLCALL
  146. xmlHashRemoveEntry(xmlHashTablePtr table, const xmlChar *name,
  147. xmlHashDeallocator f);
  148. XMLPUBFUN int XMLCALL
  149. xmlHashRemoveEntry2(xmlHashTablePtr table, const xmlChar *name,
  150. const xmlChar *name2, xmlHashDeallocator f);
  151. XMLPUBFUN int XMLCALL
  152. xmlHashRemoveEntry3(xmlHashTablePtr table, const xmlChar *name,
  153. const xmlChar *name2, const xmlChar *name3,
  154. xmlHashDeallocator f);
  155. /*
  156. * Retrieve the userdata.
  157. */
  158. XMLPUBFUN void * XMLCALL
  159. xmlHashLookup (xmlHashTablePtr table,
  160. const xmlChar *name);
  161. XMLPUBFUN void * XMLCALL
  162. xmlHashLookup2 (xmlHashTablePtr table,
  163. const xmlChar *name,
  164. const xmlChar *name2);
  165. XMLPUBFUN void * XMLCALL
  166. xmlHashLookup3 (xmlHashTablePtr table,
  167. const xmlChar *name,
  168. const xmlChar *name2,
  169. const xmlChar *name3);
  170. XMLPUBFUN void * XMLCALL
  171. xmlHashQLookup (xmlHashTablePtr table,
  172. const xmlChar *name,
  173. const xmlChar *prefix);
  174. XMLPUBFUN void * XMLCALL
  175. xmlHashQLookup2 (xmlHashTablePtr table,
  176. const xmlChar *name,
  177. const xmlChar *prefix,
  178. const xmlChar *name2,
  179. const xmlChar *prefix2);
  180. XMLPUBFUN void * XMLCALL
  181. xmlHashQLookup3 (xmlHashTablePtr table,
  182. const xmlChar *name,
  183. const xmlChar *prefix,
  184. const xmlChar *name2,
  185. const xmlChar *prefix2,
  186. const xmlChar *name3,
  187. const xmlChar *prefix3);
  188. /*
  189. * Helpers.
  190. */
  191. XMLPUBFUN xmlHashTablePtr XMLCALL
  192. xmlHashCopy (xmlHashTablePtr table,
  193. xmlHashCopier f);
  194. XMLPUBFUN int XMLCALL
  195. xmlHashSize (xmlHashTablePtr table);
  196. XMLPUBFUN void XMLCALL
  197. xmlHashScan (xmlHashTablePtr table,
  198. xmlHashScanner f,
  199. void *data);
  200. XMLPUBFUN void XMLCALL
  201. xmlHashScan3 (xmlHashTablePtr table,
  202. const xmlChar *name,
  203. const xmlChar *name2,
  204. const xmlChar *name3,
  205. xmlHashScanner f,
  206. void *data);
  207. XMLPUBFUN void XMLCALL
  208. xmlHashScanFull (xmlHashTablePtr table,
  209. xmlHashScannerFull f,
  210. void *data);
  211. XMLPUBFUN void XMLCALL
  212. xmlHashScanFull3(xmlHashTablePtr table,
  213. const xmlChar *name,
  214. const xmlChar *name2,
  215. const xmlChar *name3,
  216. xmlHashScannerFull f,
  217. void *data);
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. #endif /* ! __XML_HASH_H__ */