I've no idea here...
[gtkD.git] / src / glib / HashTable.d
blobff209057109fb478ccb5980242732d3ad7979afd
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Hash-Tables.html
26 * outPack = glib
27 * outFile = HashTable
28 * strct = GHashTable
29 * realStrct=
30 * ctorStrct=
31 * clss = HashTable
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_hash_table_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Dataset
45 * structWrap:
46 * - GHashTable* -> HashTable
47 * local aliases:
50 module glib.HashTable;
52 private import glib.glibtypes;
54 private import lib.glib;
56 private import glib.Dataset;
58 /**
59 * Description
60 * A GHashTable provides associations between keys and values which
61 * is optimized so that given a key, the associated value can be found
62 * very quickly.
63 * Note that neither keys nor values are copied when inserted into the
64 * GHashTable, so they must exist for the lifetime of the GHashTable.
65 * This means that the use of static strings is OK, but temporary
66 * strings (i.e. those created in buffers and those returned by GTK+ widgets)
67 * should be copied with g_strdup() before being inserted.
68 * If keys or values are dynamically allocated, you must be careful to ensure
69 * that they are freed when they are removed from the GHashTable, and also
70 * when they are overwritten by new insertions into the GHashTable.
71 * It is also not advisable to mix static strings and dynamically-allocated
72 * strings in a GHashTable, because it then becomes difficult to determine
73 * whether the string should be freed.
74 * To create a GHashTable, use g_hash_table_new().
75 * To insert a key and value into a GHashTable, use g_hash_table_insert().
76 * To lookup a value corresponding to a given key, use g_hash_table_lookup()
77 * and g_hash_table_lookup_extended().
78 * To remove a key and value, use g_hash_table_remove().
79 * To call a function for each key and value pair use g_hash_table_foreach().
80 * To destroy a GHashTable use g_hash_table_destroy().
82 public class HashTable
85 /** the main Gtk struct */
86 protected GHashTable* gHashTable;
89 public GHashTable* getHashTableStruct()
91 return gHashTable;
95 /** the main Gtk struct as a void* */
96 protected void* getStruct()
98 return cast(void*)gHashTable;
102 * Sets our main struct and passes it to the parent class
104 public this (GHashTable* gHashTable)
106 this.gHashTable = gHashTable;
114 * Creates a new GHashTable with a reference count of 1.
115 * hash_func:
116 * a function to create a hash value from a key.
117 * Hash values are used to determine where keys are stored within the
118 * GHashTable data structure. The g_direct_hash(), g_int_hash() and
119 * g_str_hash() functions are provided for some common types of keys.
120 * If hash_func is NULL, g_direct_hash() is used.
121 * key_equal_func:
122 * a function to check two keys for equality. This is
123 * used when looking up keys in the GHashTable. The g_direct_equal(),
124 * g_int_equal() and g_str_equal() functions are provided for the most
125 * common types of keys. If key_equal_func is NULL, keys are compared
126 * directly in a similar fashion to g_direct_equal(), but without the
127 * overhead of a function call.
128 * Returns:
129 * a new GHashTable.
131 public this (GHashFunc hashFunc, GEqualFunc keyEqualFunc)
133 // GHashTable* g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
134 this(cast(GHashTable*)g_hash_table_new(hashFunc, keyEqualFunc) );
138 * Creates a new GHashTable like g_hash_table_new() with a reference count
139 * of 1 and allows to specify functions to free the memory allocated for the
140 * key and value that get called when removing the entry from the GHashTable.
141 * hash_func:
142 * a function to create a hash value from a key.
143 * key_equal_func:
144 * a function to check two keys for equality.
145 * key_destroy_func:
146 * a function to free the memory allocated for the key
147 * used when removing the entry from the GHashTable or NULL if you
148 * don't want to supply such a function.
149 * value_destroy_func:
150 * a function to free the memory allocated for the
151 * value used when removing the entry from the GHashTable or NULL if
152 * you don't want to supply such a function.
153 * Returns:
154 * a new GHashTable.
156 public this (GHashFunc hashFunc, GEqualFunc keyEqualFunc, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)
158 // GHashTable* g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
159 this(cast(GHashTable*)g_hash_table_new_full(hashFunc, keyEqualFunc, keyDestroyFunc, valueDestroyFunc) );
165 * Inserts a new key and value into a GHashTable.
166 * If the key already exists in the GHashTable its current value is replaced
167 * with the new value. If you supplied a value_destroy_func when creating the
168 * GHashTable, the old value is freed using that function. If you supplied
169 * a key_destroy_func when creating the GHashTable, the passed key is freed
170 * using that function.
171 * hash_table:
172 * a GHashTable.
173 * key:
174 * a key to insert.
175 * value:
176 * the value to associate with the key.
178 public void insert(void* key, void* value)
180 // void g_hash_table_insert (GHashTable *hash_table, gpointer key, gpointer value);
181 g_hash_table_insert(gHashTable, key, value);
185 * Inserts a new key and value into a GHashTable similar to
186 * g_hash_table_insert(). The difference is that if the key already exists
187 * in the GHashTable, it gets replaced by the new key. If you supplied a
188 * value_destroy_func when creating the GHashTable, the old value is freed
189 * using that function. If you supplied a key_destroy_func when creating the
190 * GHashTable, the old key is freed using that function.
191 * hash_table:
192 * a GHashTable.
193 * key:
194 * a key to insert.
195 * value:
196 * the value to associate with the key.
198 public void replace(void* key, void* value)
200 // void g_hash_table_replace (GHashTable *hash_table, gpointer key, gpointer value);
201 g_hash_table_replace(gHashTable, key, value);
205 * Returns the number of elements contained in the GHashTable.
206 * hash_table:
207 * a GHashTable.
208 * Returns:
209 * the number of key/value pairs in the GHashTable.
211 public uint size()
213 // guint g_hash_table_size (GHashTable *hash_table);
214 return g_hash_table_size(gHashTable);
218 * Looks up a key in a GHashTable. Note that this function cannot
219 * distinguish between a key that is not present and one which is present
220 * and has the value NULL. If you need this distinction, use
221 * g_hash_table_lookup_extended().
222 * hash_table:
223 * a GHashTable.
224 * key:
225 * the key to look up.
226 * Returns:
227 * the associated value, or NULL if the key is not found.
229 public void* lookup(void* key)
231 // gpointer g_hash_table_lookup (GHashTable *hash_table, gconstpointer key);
232 return g_hash_table_lookup(gHashTable, key);
236 * Looks up a key in the GHashTable, returning the original key and the
237 * associated value and a gboolean which is TRUE if the key was found. This
238 * is useful if you need to free the memory allocated for the original key,
239 * for example before calling g_hash_table_remove().
240 * hash_table:
241 * a GHashTable.
242 * lookup_key:
243 * the key to look up.
244 * orig_key:
245 * returns the original key.
246 * value:
247 * returns the value associated with the key.
248 * Returns:
249 * TRUE if the key was found in the GHashTable.
251 public int lookupExtended(void* lookupKey, void** origKey, void** value)
253 // gboolean g_hash_table_lookup_extended (GHashTable *hash_table, gconstpointer lookup_key, gpointer *orig_key, gpointer *value);
254 return g_hash_table_lookup_extended(gHashTable, lookupKey, origKey, value);
258 * Calls the given function for each of the key/value pairs in the
259 * GHashTable. The function is passed the key and value of each
260 * pair, and the given user_data parameter. The hash table may not
261 * be modified while iterating over it (you can't add/remove
262 * items). To remove all items matching a predicate, use
263 * g_hash_table_foreach_remove().
264 * hash_table:
265 * a GHashTable.
266 * func:
267 * the function to call for each key/value pair.
268 * user_data:
269 * user data to pass to the function.
271 public void foreac(GHFunc func, void* userData)
273 // void g_hash_table_foreach (GHashTable *hash_table, GHFunc func, gpointer user_data);
274 g_hash_table_foreach(gHashTable, func, userData);
278 * Calls the given function for key/value pairs in the GHashTable until
279 * predicate returns TRUE. The function is passed the key and value of
280 * each pair, and the given user_data parameter. The hash table may not
281 * be modified while iterating over it (you can't add/remove items).
282 * hash_table:
283 * a GHashTable.
284 * predicate:
285 * function to test the key/value pairs for a certain property.
286 * user_data:
287 * user data to pass to the function.
288 * Returns:
289 * The value of the first key/value pair is returned, for which
290 * func evaluates to TRUE. If no pair with the requested property is found,
291 * NULL is returned.
292 * Since 2.4
294 public void* find(GHRFunc predicate, void* userData)
296 // gpointer g_hash_table_find (GHashTable *hash_table, GHRFunc predicate, gpointer user_data);
297 return g_hash_table_find(gHashTable, predicate, userData);
302 * Removes a key and its associated value from a GHashTable.
303 * If the GHashTable was created using g_hash_table_new_full(), the
304 * key and value are freed using the supplied destroy functions, otherwise
305 * you have to make sure that any dynamically allocated values are freed
306 * yourself.
307 * hash_table:
308 * a GHashTable.
309 * key:
310 * the key to remove.
311 * Returns:
312 * TRUE if the key was found and removed from the GHashTable.
314 public int remove(void* key)
316 // gboolean g_hash_table_remove (GHashTable *hash_table, gconstpointer key);
317 return g_hash_table_remove(gHashTable, key);
321 * Removes a key and its associated value from a GHashTable without
322 * calling the key and value destroy functions.
323 * hash_table:
324 * a GHashTable.
325 * key:
326 * the key to remove.
327 * Returns:
328 * TRUE if the key was found and removed from the GHashTable.
330 public int steal(void* key)
332 // gboolean g_hash_table_steal (GHashTable *hash_table, gconstpointer key);
333 return g_hash_table_steal(gHashTable, key);
337 * Calls the given function for each key/value pair in the GHashTable.
338 * If the function returns TRUE, then the key/value pair is removed from the
339 * GHashTable. If you supplied key or value destroy functions when creating
340 * the GHashTable, they are used to free the memory allocated for the removed
341 * keys and values.
342 * hash_table:
343 * a GHashTable.
344 * func:
345 * the function to call for each key/value pair.
346 * user_data:
347 * user data to pass to the function.
348 * Returns:
349 * the number of key/value pairs removed.
351 public uint foreachRemove(GHRFunc func, void* userData)
353 // guint g_hash_table_foreach_remove (GHashTable *hash_table, GHRFunc func, gpointer user_data);
354 return g_hash_table_foreach_remove(gHashTable, func, userData);
358 * Calls the given function for each key/value pair in the GHashTable.
359 * If the function returns TRUE, then the key/value pair is removed from the
360 * GHashTable, but no key or value destroy functions are called.
361 * hash_table:
362 * a GHashTable.
363 * func:
364 * the function to call for each key/value pair.
365 * user_data:
366 * user data to pass to the function.
367 * Returns:
368 * the number of key/value pairs removed.
370 public uint foreachSteal(GHRFunc func, void* userData)
372 // guint g_hash_table_foreach_steal (GHashTable *hash_table, GHRFunc func, gpointer user_data);
373 return g_hash_table_foreach_steal(gHashTable, func, userData);
377 * Removes all keys and their associated values from a GHashTable.
378 * If the GHashTable was created using g_hash_table_new_full(), the keys
379 * and values are freed using the supplied destroy functions, otherwise you
380 * have to make sure that any dynamically allocated values are freed
381 * yourself.
382 * hash_table:
383 * a GHashTable
384 * Since 2.12
386 public void removeAll()
388 // void g_hash_table_remove_all (GHashTable *hash_table);
389 g_hash_table_remove_all(gHashTable);
393 * Removes all keys and their associated values from a GHashTable
394 * without calling the key and value destroy functions.
395 * hash_table:
396 * a GHashTable.
397 * Since 2.12
399 public void stealAll()
401 // void g_hash_table_steal_all (GHashTable *hash_table);
402 g_hash_table_steal_all(gHashTable);
409 * Destroys all keys and values in the GHashTable and decrements its
410 * reference count by 1. If keys and/or values are dynamically allocated,
411 * you should either free them first or create the GHashTable with destroy
412 * notifiers using g_hash_table_new_full(). In the latter case the destroy
413 * functions you supplied will be called on all keys and values during the
414 * destruction phase.
415 * hash_table:
416 * a GHashTable.
418 public void destroy()
420 // void g_hash_table_destroy (GHashTable *hash_table);
421 g_hash_table_destroy(gHashTable);
425 * Atomically increments the reference count of hash_table by one.
426 * This function is MT-safe and may be called from any thread.
427 * hash_table:
428 * a valid GHashTable.
429 * Returns:
430 * the passed in GHashTable.
431 * Since 2.10
433 public HashTable ref()
435 // GHashTable* g_hash_table_ref (GHashTable *hash_table);
436 return new HashTable( g_hash_table_ref(gHashTable) );
440 * Atomically decrements the reference count of hash_table by one.
441 * If the reference count drops to 0, all keys and values will be
442 * destroyed, and all memory allocated by the hash table is released.
443 * This function is MT-safe and may be called from any thread.
444 * hash_table:
445 * a valid GHashTable.
446 * Since 2.10
448 public void unref()
450 // void g_hash_table_unref (GHashTable *hash_table);
451 g_hash_table_unref(gHashTable);
455 * Compares two gpointer arguments and returns TRUE if they are equal.
456 * It can be passed to g_hash_table_new() as the key_equal_func
457 * parameter, when using pointers as keys in a GHashTable.
458 * v1:
459 * a key.
460 * v2:
461 * a key to compare with v1.
462 * Returns:
463 * TRUE if the two keys match.
465 public static int gDirectEqual(void* v1, void* v2)
467 // gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
468 return g_direct_equal(v1, v2);
472 * Converts a gpointer to a hash value.
473 * It can be passed to g_hash_table_new() as the hash_func parameter,
474 * when using pointers as keys in a GHashTable.
475 * v:
476 * a gpointer key
477 * Returns:
478 * a hash value corresponding to the key.
480 public static uint gDirectHash(void* v)
482 // guint g_direct_hash (gconstpointer v);
483 return g_direct_hash(v);
487 * Compares the two gint values being pointed to and returns
488 * TRUE if they are equal.
489 * It can be passed to g_hash_table_new() as the key_equal_func
490 * parameter, when using pointers to integers as keys in a GHashTable.
491 * v1:
492 * a pointer to a gint key.
493 * v2:
494 * a pointer to a gint key to compare with v1.
495 * Returns:
496 * TRUE if the two keys match.
498 public static int gIntEqual(void* v1, void* v2)
500 // gboolean g_int_equal (gconstpointer v1, gconstpointer v2);
501 return g_int_equal(v1, v2);
505 * Converts a pointer to a gint to a hash value.
506 * It can be passed to g_hash_table_new() as the hash_func parameter,
507 * when using pointers to integers values as keys in a GHashTable.
508 * v:
509 * a pointer to a gint key
510 * Returns:
511 * a hash value corresponding to the key.
513 public static uint gIntHash(void* v)
515 // guint g_int_hash (gconstpointer v);
516 return g_int_hash(v);
520 * Compares two strings and returns TRUE if they are equal.
521 * It can be passed to g_hash_table_new() as the key_equal_func
522 * parameter, when using strings as keys in a GHashTable.
523 * v1:
524 * a key.
525 * v2:
526 * a key to compare with v1.
527 * Returns:
528 * TRUE if the two keys match.
530 public static int gStrEqual(void* v1, void* v2)
532 // gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
533 return g_str_equal(v1, v2);
537 * Converts a string to a hash value.
538 * It can be passed to g_hash_table_new() as the hash_func parameter,
539 * when using strings as keys in a GHashTable.
540 * v:
541 * a string key.
542 * Returns:
543 * a hash value corresponding to the key.
545 public static uint gStrHash(void* v)
547 // guint g_str_hash (gconstpointer v);
548 return g_str_hash(v);