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