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