1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = 27 * outPack = glib 28 * outFile = HashTableIter 29 * strct = GHashTableIter 30 * realStrct= 31 * ctorStrct= 32 * clss = HashTableIter 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_hash_table_iter_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.HashTable 47 * structWrap: 48 * - GHashTable* -> HashTable 49 * module aliases: 50 * local aliases: 51 * overrides: 52 */ 53 54 module glib.HashTableIter; 55 56 public import gtkc.glibtypes; 57 58 private import gtkc.glib; 59 private import glib.ConstructionException; 60 61 private import glib.HashTable; 62 63 64 65 /** 66 * A GHashTable provides associations between keys and values which is 67 * optimized so that given a key, the associated value can be found 68 * very quickly. 69 * 70 * Note that neither keys nor values are copied when inserted into the 71 * GHashTable, so they must exist for the lifetime of the GHashTable. 72 * This means that the use of static strings is OK, but temporary 73 * strings (i.e. those created in buffers and those returned by GTK+ 74 * widgets) should be copied with g_strdup() before being inserted. 75 * 76 * If keys or values are dynamically allocated, you must be careful to 77 * ensure that they are freed when they are removed from the 78 * GHashTable, and also when they are overwritten by new insertions 79 * into the GHashTable. It is also not advisable to mix static strings 80 * and dynamically-allocated strings in a GHashTable, because it then 81 * becomes difficult to determine whether the string should be freed. 82 * 83 * To create a GHashTable, use g_hash_table_new(). 84 * 85 * To insert a key and value into a GHashTable, use 86 * g_hash_table_insert(). 87 * 88 * To lookup a value corresponding to a given key, use 89 * g_hash_table_lookup() and g_hash_table_lookup_extended(). 90 * 91 * g_hash_table_lookup_extended() can also be used to simply 92 * check if a key is present in the hash table. 93 * 94 * To remove a key and value, use g_hash_table_remove(). 95 * 96 * To call a function for each key and value pair use 97 * g_hash_table_foreach() or use a iterator to iterate over the 98 * key/value pairs in the hash table, see GHashTableIter. 99 * 100 * To destroy a GHashTable use g_hash_table_destroy(). 101 * 102 * A common use-case for hash tables is to store information about a 103 * set of keys, without associating any particular value with each 104 * key. GHashTable optimizes one way of doing so: If you store only 105 * key-value pairs where key == value, then GHashTable does not 106 * allocate memory to store the values, which can be a considerable 107 * space saving, if your set is large. The functions 108 * g_hash_table_add() and g_hash_table_contains() are designed to be 109 * used when using GHashTable this way. 110 */ 111 public class HashTableIter 112 { 113 114 /** the main Gtk struct */ 115 protected GHashTableIter* gHashTableIter; 116 117 118 /** Get the main Gtk struct */ 119 public GHashTableIter* getHashTableIterStruct() 120 { 121 return gHashTableIter; 122 } 123 124 125 /** the main Gtk struct as a void* */ 126 protected void* getStruct() 127 { 128 return cast(void*)gHashTableIter; 129 } 130 131 /** 132 * Sets our main struct and passes it to the parent class 133 */ 134 public this (GHashTableIter* gHashTableIter) 135 { 136 this.gHashTableIter = gHashTableIter; 137 } 138 139 /** 140 */ 141 142 /** 143 * Initializes a key/value pair iterator and associates it with 144 * hash_table. Modifying the hash table after calling this function 145 * invalidates the returned iterator. 146 * $(DDOC_COMMENT example) 147 * Since 2.16 148 * Params: 149 * hashTable = a GHashTable 150 */ 151 public void init(HashTable hashTable) 152 { 153 // void g_hash_table_iter_init (GHashTableIter *iter, GHashTable *hash_table); 154 g_hash_table_iter_init(gHashTableIter, (hashTable is null) ? null : hashTable.getHashTableStruct()); 155 } 156 157 /** 158 * Advances iter and retrieves the key and/or value that are now 159 * pointed to as a result of this advancement. If FALSE is returned, 160 * key and value are not set, and the iterator becomes invalid. 161 * Since 2.16 162 * Params: 163 * key = a location to store the key, or NULL. [allow-none] 164 * value = a location to store the value, or NULL. [allow-none] 165 * Returns: FALSE if the end of the GHashTable has been reached. 166 */ 167 public int next(void** key, void** value) 168 { 169 // gboolean g_hash_table_iter_next (GHashTableIter *iter, gpointer *key, gpointer *value); 170 return g_hash_table_iter_next(gHashTableIter, key, value); 171 } 172 173 /** 174 * Returns the GHashTable associated with iter. 175 * Since 2.16 176 * Returns: the GHashTable associated with iter. 177 */ 178 public HashTable getHashTable() 179 { 180 // GHashTable * g_hash_table_iter_get_hash_table (GHashTableIter *iter); 181 auto p = g_hash_table_iter_get_hash_table(gHashTableIter); 182 183 if(p is null) 184 { 185 return null; 186 } 187 188 return new HashTable(cast(GHashTable*) p); 189 } 190 191 /** 192 * Replaces the value currently pointed to by the iterator 193 * from its associated GHashTable. Can only be called after 194 * g_hash_table_iter_next() returned TRUE. 195 * If you supplied a value_destroy_func when creating the 196 * GHashTable, the old value is freed using that function. 197 * Since 2.30 198 * Params: 199 * value = the value to replace with 200 */ 201 public void replace(void* value) 202 { 203 // void g_hash_table_iter_replace (GHashTableIter *iter, gpointer value); 204 g_hash_table_iter_replace(gHashTableIter, value); 205 } 206 207 /** 208 * Removes the key/value pair currently pointed to by the iterator 209 * from its associated GHashTable. Can only be called after 210 * g_hash_table_iter_next() returned TRUE, and cannot be called 211 * more than once for the same key/value pair. 212 * If the GHashTable was created using g_hash_table_new_full(), 213 * the key and value are freed using the supplied destroy functions, 214 * otherwise you have to make sure that any dynamically allocated 215 * values are freed yourself. 216 * Since 2.16 217 */ 218 public void remove() 219 { 220 // void g_hash_table_iter_remove (GHashTableIter *iter); 221 g_hash_table_iter_remove(gHashTableIter); 222 } 223 224 /** 225 * Removes the key/value pair currently pointed to by the 226 * iterator from its associated GHashTable, without calling 227 * the key and value destroy functions. Can only be called 228 * after g_hash_table_iter_next() returned TRUE, and cannot 229 * be called more than once for the same key/value pair. 230 * Since 2.16 231 */ 232 public void steal() 233 { 234 // void g_hash_table_iter_steal (GHashTableIter *iter); 235 g_hash_table_iter_steal(gHashTableIter); 236 } 237 }