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 module glib.HashTableIter; 26 27 private import glib.HashTable; 28 private import glib.c.functions; 29 public import glib.c.types; 30 public import gtkc.glibtypes; 31 32 33 /** 34 * A GHashTableIter structure represents an iterator that can be used 35 * to iterate over the elements of a #GHashTable. GHashTableIter 36 * structures are typically allocated on the stack and then initialized 37 * with g_hash_table_iter_init(). 38 * 39 * The iteration order of a #GHashTableIter over the keys/values in a hash 40 * table is not defined. 41 */ 42 public class HashTableIter 43 { 44 /** the main Gtk struct */ 45 protected GHashTableIter* gHashTableIter; 46 protected bool ownedRef; 47 48 /** Get the main Gtk struct */ 49 public GHashTableIter* getHashTableIterStruct(bool transferOwnership = false) 50 { 51 if (transferOwnership) 52 ownedRef = false; 53 return gHashTableIter; 54 } 55 56 /** the main Gtk struct as a void* */ 57 protected void* getStruct() 58 { 59 return cast(void*)gHashTableIter; 60 } 61 62 /** 63 * Sets our main struct and passes it to the parent class. 64 */ 65 public this (GHashTableIter* gHashTableIter, bool ownedRef = false) 66 { 67 this.gHashTableIter = gHashTableIter; 68 this.ownedRef = ownedRef; 69 } 70 71 72 /** 73 * Returns the #GHashTable associated with @iter. 74 * 75 * Returns: the #GHashTable associated with @iter. 76 * 77 * Since: 2.16 78 */ 79 public HashTable getHashTable() 80 { 81 auto __p = g_hash_table_iter_get_hash_table(gHashTableIter); 82 83 if(__p is null) 84 { 85 return null; 86 } 87 88 return new HashTable(cast(GHashTable*) __p); 89 } 90 91 /** 92 * Initializes a key/value pair iterator and associates it with 93 * @hash_table. Modifying the hash table after calling this function 94 * invalidates the returned iterator. 95 * 96 * The iteration order of a #GHashTableIter over the keys/values in a hash 97 * table is not defined. 98 * 99 * |[<!-- language="C" --> 100 * GHashTableIter iter; 101 * gpointer key, value; 102 * 103 * g_hash_table_iter_init (&iter, hash_table); 104 * while (g_hash_table_iter_next (&iter, &key, &value)) 105 * { 106 * // do something with key and value 107 * } 108 * ]| 109 * 110 * Params: 111 * hashTable = a #GHashTable 112 * 113 * Since: 2.16 114 */ 115 public void init(HashTable hashTable) 116 { 117 g_hash_table_iter_init(gHashTableIter, (hashTable is null) ? null : hashTable.getHashTableStruct()); 118 } 119 120 /** 121 * Advances @iter and retrieves the key and/or value that are now 122 * pointed to as a result of this advancement. If %FALSE is returned, 123 * @key and @value are not set, and the iterator becomes invalid. 124 * 125 * Params: 126 * key = a location to store the key 127 * value = a location to store the value 128 * 129 * Returns: %FALSE if the end of the #GHashTable has been reached. 130 * 131 * Since: 2.16 132 */ 133 public bool next(out void* key, out void* value) 134 { 135 return g_hash_table_iter_next(gHashTableIter, &key, &value) != 0; 136 } 137 138 /** 139 * Removes the key/value pair currently pointed to by the iterator 140 * from its associated #GHashTable. Can only be called after 141 * g_hash_table_iter_next() returned %TRUE, and cannot be called 142 * more than once for the same key/value pair. 143 * 144 * If the #GHashTable was created using g_hash_table_new_full(), 145 * the key and value are freed using the supplied destroy functions, 146 * otherwise you have to make sure that any dynamically allocated 147 * values are freed yourself. 148 * 149 * It is safe to continue iterating the #GHashTable afterward: 150 * |[<!-- language="C" --> 151 * while (g_hash_table_iter_next (&iter, &key, &value)) 152 * { 153 * if (condition) 154 * g_hash_table_iter_remove (&iter); 155 * } 156 * ]| 157 * 158 * Since: 2.16 159 */ 160 public void remove() 161 { 162 g_hash_table_iter_remove(gHashTableIter); 163 } 164 165 /** 166 * Replaces the value currently pointed to by the iterator 167 * from its associated #GHashTable. Can only be called after 168 * g_hash_table_iter_next() returned %TRUE. 169 * 170 * If you supplied a @value_destroy_func when creating the 171 * #GHashTable, the old value is freed using that function. 172 * 173 * Params: 174 * value = the value to replace with 175 * 176 * Since: 2.30 177 */ 178 public void replace(void* value) 179 { 180 g_hash_table_iter_replace(gHashTableIter, value); 181 } 182 183 /** 184 * Removes the key/value pair currently pointed to by the 185 * iterator from its associated #GHashTable, without calling 186 * the key and value destroy functions. Can only be called 187 * after g_hash_table_iter_next() returned %TRUE, and cannot 188 * be called more than once for the same key/value pair. 189 * 190 * Since: 2.16 191 */ 192 public void steal() 193 { 194 g_hash_table_iter_steal(gHashTableIter); 195 } 196 }