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