2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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
46 * - GHashTable* -> HashTable
51 module glib
.HashTable
;
57 import tango
.io
.Stdout
; // use the tango loging?
61 private import gtkc
.glibtypes
;
63 private import gtkc
.glib
;
66 private import glib
.Dataset
;
73 * A GHashTable provides associations between keys and values which
74 * is optimized so that given a key, the associated value can be found
76 * Note that neither keys nor values are copied when inserted into the
77 * GHashTable, so they must exist for the lifetime of the GHashTable.
78 * This means that the use of static strings is OK, but temporary
79 * strings (i.e. those created in buffers and those returned by GTK+ widgets)
80 * should be copied with g_strdup() before being inserted.
81 * If keys or values are dynamically allocated, you must be careful to ensure
82 * that they are freed when they are removed from the GHashTable, and also
83 * when they are overwritten by new insertions into the GHashTable.
84 * It is also not advisable to mix static strings and dynamically-allocated
85 * strings in a GHashTable, because it then becomes difficult to determine
86 * whether the string should be freed.
87 * To create a GHashTable, use g_hash_table_new().
88 * To insert a key and value into a GHashTable, use g_hash_table_insert().
89 * To lookup a value corresponding to a given key, use g_hash_table_lookup()
90 * and g_hash_table_lookup_extended().
91 * To remove a key and value, use g_hash_table_remove().
92 * To call a function for each key and value pair use g_hash_table_foreach().
93 * To destroy a GHashTable use g_hash_table_destroy().
95 public class HashTable
98 /** the main Gtk struct */
99 protected GHashTable
* gHashTable
;
102 public GHashTable
* getHashTableStruct()
108 /** the main Gtk struct as a void* */
109 protected void* getStruct()
111 return cast(void*)gHashTable
;
115 * Sets our main struct and passes it to the parent class
117 public this (GHashTable
* gHashTable
)
121 if ( gHashTable
is null )
126 Stdout("struct gHashTable is null on constructor").newline
;
130 printf("struct gHashTable is null on constructor");
137 assert(gHashTable
!is null, "struct gHashTable is null on constructor");
139 this.gHashTable
= gHashTable
;
147 * Creates a new GHashTable with a reference count of 1.
149 * a function to create a hash value from a key.
150 * Hash values are used to determine where keys are stored within the
151 * GHashTable data structure. The g_direct_hash(), g_int_hash() and
152 * g_str_hash() functions are provided for some common types of keys.
153 * If hash_func is NULL, g_direct_hash() is used.
155 * a function to check two keys for equality. This is
156 * used when looking up keys in the GHashTable. The g_direct_equal(),
157 * g_int_equal() and g_str_equal() functions are provided for the most
158 * common types of keys. If key_equal_func is NULL, keys are compared
159 * directly in a similar fashion to g_direct_equal(), but without the
160 * overhead of a function call.
164 public this (GHashFunc hashFunc
, GEqualFunc keyEqualFunc
)
166 // GHashTable* g_hash_table_new (GHashFunc hash_func, GEqualFunc key_equal_func);
167 this(cast(GHashTable
*)g_hash_table_new(hashFunc
, keyEqualFunc
) );
171 * Creates a new GHashTable like g_hash_table_new() with a reference count
172 * of 1 and allows to specify functions to free the memory allocated for the
173 * key and value that get called when removing the entry from the GHashTable.
175 * a function to create a hash value from a key.
177 * a function to check two keys for equality.
179 * a function to free the memory allocated for the key
180 * used when removing the entry from the GHashTable or NULL if you
181 * don't want to supply such a function.
182 * value_destroy_func:
183 * a function to free the memory allocated for the
184 * value used when removing the entry from the GHashTable or NULL if
185 * you don't want to supply such a function.
189 public this (GHashFunc hashFunc
, GEqualFunc keyEqualFunc
, GDestroyNotify keyDestroyFunc
, GDestroyNotify valueDestroyFunc
)
191 // GHashTable* g_hash_table_new_full (GHashFunc hash_func, GEqualFunc key_equal_func, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
192 this(cast(GHashTable
*)g_hash_table_new_full(hashFunc
, keyEqualFunc
, keyDestroyFunc
, valueDestroyFunc
) );
198 * Inserts a new key and value into a GHashTable.
199 * If the key already exists in the GHashTable its current value is replaced
200 * with the new value. If you supplied a value_destroy_func when creating the
201 * GHashTable, the old value is freed using that function. If you supplied
202 * a key_destroy_func when creating the GHashTable, the passed key is freed
203 * using that function.
209 * the value to associate with the key.
211 public void insert(void* key
, void* value
)
213 // void g_hash_table_insert (GHashTable *hash_table, gpointer key, gpointer value);
214 g_hash_table_insert(gHashTable
, key
, value
);
218 * Inserts a new key and value into a GHashTable similar to
219 * g_hash_table_insert(). The difference is that if the key already exists
220 * in the GHashTable, it gets replaced by the new key. If you supplied a
221 * value_destroy_func when creating the GHashTable, the old value is freed
222 * using that function. If you supplied a key_destroy_func when creating the
223 * GHashTable, the old key is freed using that function.
229 * the value to associate with the key.
231 public void replace(void* key
, void* value
)
233 // void g_hash_table_replace (GHashTable *hash_table, gpointer key, gpointer value);
234 g_hash_table_replace(gHashTable
, key
, value
);
238 * Returns the number of elements contained in the GHashTable.
242 * the number of key/value pairs in the GHashTable.
246 // guint g_hash_table_size (GHashTable *hash_table);
247 return g_hash_table_size(gHashTable
);
251 * Looks up a key in a GHashTable. Note that this function cannot
252 * distinguish between a key that is not present and one which is present
253 * and has the value NULL. If you need this distinction, use
254 * g_hash_table_lookup_extended().
258 * the key to look up.
260 * the associated value, or NULL if the key is not found.
262 public void* lookup(void* key
)
264 // gpointer g_hash_table_lookup (GHashTable *hash_table, gconstpointer key);
265 return g_hash_table_lookup(gHashTable
, key
);
269 * Looks up a key in the GHashTable, returning the original key and the
270 * associated value and a gboolean which is TRUE if the key was found. This
271 * is useful if you need to free the memory allocated for the original key,
272 * for example before calling g_hash_table_remove().
276 * the key to look up.
278 * returns the original key.
280 * returns the value associated with the key.
282 * TRUE if the key was found in the GHashTable.
284 public int lookupExtended(void* lookupKey
, void** origKey
, void** value
)
286 // gboolean g_hash_table_lookup_extended (GHashTable *hash_table, gconstpointer lookup_key, gpointer *orig_key, gpointer *value);
287 return g_hash_table_lookup_extended(gHashTable
, lookupKey
, origKey
, value
);
291 * Calls the given function for each of the key/value pairs in the
292 * GHashTable. The function is passed the key and value of each
293 * pair, and the given user_data parameter. The hash table may not
294 * be modified while iterating over it (you can't add/remove
295 * items). To remove all items matching a predicate, use
296 * g_hash_table_foreach_remove().
300 * the function to call for each key/value pair.
302 * user data to pass to the function.
304 public void foreac(GHFunc func
, void* userData
)
306 // void g_hash_table_foreach (GHashTable *hash_table, GHFunc func, gpointer user_data);
307 g_hash_table_foreach(gHashTable
, func
, userData
);
311 * Calls the given function for key/value pairs in the GHashTable until
312 * predicate returns TRUE. The function is passed the key and value of
313 * each pair, and the given user_data parameter. The hash table may not
314 * be modified while iterating over it (you can't add/remove items).
318 * function to test the key/value pairs for a certain property.
320 * user data to pass to the function.
322 * The value of the first key/value pair is returned, for which
323 * func evaluates to TRUE. If no pair with the requested property is found,
327 public void* find(GHRFunc predicate
, void* userData
)
329 // gpointer g_hash_table_find (GHashTable *hash_table, GHRFunc predicate, gpointer user_data);
330 return g_hash_table_find(gHashTable
, predicate
, userData
);
335 * Removes a key and its associated value from a GHashTable.
336 * If the GHashTable was created using g_hash_table_new_full(), the
337 * key and value are freed using the supplied destroy functions, otherwise
338 * you have to make sure that any dynamically allocated values are freed
345 * TRUE if the key was found and removed from the GHashTable.
347 public int remove(void* key
)
349 // gboolean g_hash_table_remove (GHashTable *hash_table, gconstpointer key);
350 return g_hash_table_remove(gHashTable
, key
);
354 * Removes a key and its associated value from a GHashTable without
355 * calling the key and value destroy functions.
361 * TRUE if the key was found and removed from the GHashTable.
363 public int steal(void* key
)
365 // gboolean g_hash_table_steal (GHashTable *hash_table, gconstpointer key);
366 return g_hash_table_steal(gHashTable
, key
);
370 * Calls the given function for each key/value pair in the GHashTable.
371 * If the function returns TRUE, then the key/value pair is removed from the
372 * GHashTable. If you supplied key or value destroy functions when creating
373 * the GHashTable, they are used to free the memory allocated for the removed
378 * the function to call for each key/value pair.
380 * user data to pass to the function.
382 * the number of key/value pairs removed.
384 public uint foreachRemove(GHRFunc func
, void* userData
)
386 // guint g_hash_table_foreach_remove (GHashTable *hash_table, GHRFunc func, gpointer user_data);
387 return g_hash_table_foreach_remove(gHashTable
, func
, userData
);
391 * Calls the given function for each key/value pair in the GHashTable.
392 * If the function returns TRUE, then the key/value pair is removed from the
393 * GHashTable, but no key or value destroy functions are called.
397 * the function to call for each key/value pair.
399 * user data to pass to the function.
401 * the number of key/value pairs removed.
403 public uint foreachSteal(GHRFunc func
, void* userData
)
405 // guint g_hash_table_foreach_steal (GHashTable *hash_table, GHRFunc func, gpointer user_data);
406 return g_hash_table_foreach_steal(gHashTable
, func
, userData
);
410 * Removes all keys and their associated values from a GHashTable.
411 * If the GHashTable was created using g_hash_table_new_full(), the keys
412 * and values are freed using the supplied destroy functions, otherwise you
413 * have to make sure that any dynamically allocated values are freed
419 public void removeAll()
421 // void g_hash_table_remove_all (GHashTable *hash_table);
422 g_hash_table_remove_all(gHashTable
);
426 * Removes all keys and their associated values from a GHashTable
427 * without calling the key and value destroy functions.
432 public void stealAll()
434 // void g_hash_table_steal_all (GHashTable *hash_table);
435 g_hash_table_steal_all(gHashTable
);
442 * Destroys all keys and values in the GHashTable and decrements its
443 * reference count by 1. If keys and/or values are dynamically allocated,
444 * you should either free them first or create the GHashTable with destroy
445 * notifiers using g_hash_table_new_full(). In the latter case the destroy
446 * functions you supplied will be called on all keys and values during the
451 public void destroy()
453 // void g_hash_table_destroy (GHashTable *hash_table);
454 g_hash_table_destroy(gHashTable
);
458 * Atomically increments the reference count of hash_table by one.
459 * This function is MT-safe and may be called from any thread.
461 * a valid GHashTable.
463 * the passed in GHashTable.
466 public HashTable
doref()
468 // GHashTable* g_hash_table_ref (GHashTable *hash_table);
469 return new HashTable( g_hash_table_ref(gHashTable
) );
473 * Atomically decrements the reference count of hash_table by one.
474 * If the reference count drops to 0, all keys and values will be
475 * destroyed, and all memory allocated by the hash table is released.
476 * This function is MT-safe and may be called from any thread.
478 * a valid GHashTable.
483 // void g_hash_table_unref (GHashTable *hash_table);
484 g_hash_table_unref(gHashTable
);
488 * Compares two gpointer arguments and returns 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 as keys in a GHashTable.
494 * a key to compare with v1.
496 * TRUE if the two keys match.
498 public static int gDirectEqual(void* v1
, void* v2
)
500 // gboolean g_direct_equal (gconstpointer v1, gconstpointer v2);
501 return g_direct_equal(v1
, v2
);
505 * Converts a gpointer to a hash value.
506 * It can be passed to g_hash_table_new() as the hash_func parameter,
507 * when using pointers as keys in a GHashTable.
511 * a hash value corresponding to the key.
513 public static uint gDirectHash(void* v
)
515 // guint g_direct_hash (gconstpointer v);
516 return g_direct_hash(v
);
520 * Compares the two gint values being pointed to and returns
521 * TRUE if they are equal.
522 * It can be passed to g_hash_table_new() as the key_equal_func
523 * parameter, when using pointers to integers as keys in a GHashTable.
525 * a pointer to a gint key.
527 * a pointer to a gint key to compare with v1.
529 * TRUE if the two keys match.
531 public static int gIntEqual(void* v1
, void* v2
)
533 // gboolean g_int_equal (gconstpointer v1, gconstpointer v2);
534 return g_int_equal(v1
, v2
);
538 * Converts a pointer to a gint to a hash value.
539 * It can be passed to g_hash_table_new() as the hash_func parameter,
540 * when using pointers to integers values as keys in a GHashTable.
542 * a pointer to a gint key
544 * a hash value corresponding to the key.
546 public static uint gIntHash(void* v
)
548 // guint g_int_hash (gconstpointer v);
549 return g_int_hash(v
);
553 * Compares two strings and returns TRUE if they are equal.
554 * It can be passed to g_hash_table_new() as the key_equal_func
555 * parameter, when using strings as keys in a GHashTable.
559 * a key to compare with v1.
561 * TRUE if the two keys match.
563 public static int gStrEqual(void* v1
, void* v2
)
565 // gboolean g_str_equal (gconstpointer v1, gconstpointer v2);
566 return g_str_equal(v1
, v2
);
570 * Converts a string to a hash value.
571 * It can be passed to g_hash_table_new() as the hash_func parameter,
572 * when using strings as keys in a GHashTable.
576 * a hash value corresponding to the key.
578 public static uint gStrHash(void* v
)
580 // guint g_str_hash (gconstpointer v);
581 return g_str_hash(v
);