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 
62 private import glib.HashTable;
63 
64 
65 
66 
67 /**
68  * A GHashTable provides associations between keys and values which is
69  * optimized so that given a key, the associated value can be found
70  * very quickly.
71  *
72  * Note that neither keys nor values are copied when inserted into the
73  * GHashTable, so they must exist for the lifetime of the GHashTable.
74  * This means that the use of static strings is OK, but temporary
75  * strings (i.e. those created in buffers and those returned by GTK+
76  * widgets) should be copied with g_strdup() before being inserted.
77  *
78  * If keys or values are dynamically allocated, you must be careful to
79  * ensure that they are freed when they are removed from the
80  * GHashTable, and also when they are overwritten by new insertions
81  * into the GHashTable. It is also not advisable to mix static strings
82  * and dynamically-allocated strings in a GHashTable, because it then
83  * becomes difficult to determine whether the string should be freed.
84  *
85  * To create a GHashTable, use g_hash_table_new().
86  *
87  * To insert a key and value into a GHashTable, use
88  * g_hash_table_insert().
89  *
90  * To lookup a value corresponding to a given key, use
91  * g_hash_table_lookup() and g_hash_table_lookup_extended().
92  *
93  * g_hash_table_lookup_extended() can also be used to simply
94  * check if a key is present in the hash table.
95  *
96  * To remove a key and value, use g_hash_table_remove().
97  *
98  * To call a function for each key and value pair use
99  * g_hash_table_foreach() or use a iterator to iterate over the
100  * key/value pairs in the hash table, see GHashTableIter.
101  *
102  * To destroy a GHashTable use g_hash_table_destroy().
103  *
104  * A common use-case for hash tables is to store information about a
105  * set of keys, without associating any particular value with each
106  * key. GHashTable optimizes one way of doing so: If you store only
107  * key-value pairs where key == value, then GHashTable does not
108  * allocate memory to store the values, which can be a considerable
109  * space saving, if your set is large. The functions
110  * g_hash_table_add() and g_hash_table_contains() are designed to be
111  * used when using GHashTable this way.
112  */
113 public class HashTableIter
114 {
115 	
116 	/** the main Gtk struct */
117 	protected GHashTableIter* gHashTableIter;
118 	
119 	
120 	public GHashTableIter* getHashTableIterStruct()
121 	{
122 		return gHashTableIter;
123 	}
124 	
125 	
126 	/** the main Gtk struct as a void* */
127 	protected void* getStruct()
128 	{
129 		return cast(void*)gHashTableIter;
130 	}
131 	
132 	/**
133 	 * Sets our main struct and passes it to the parent class
134 	 */
135 	public this (GHashTableIter* gHashTableIter)
136 	{
137 		this.gHashTableIter = gHashTableIter;
138 	}
139 	
140 	/**
141 	 */
142 	
143 	/**
144 	 * Initializes a key/value pair iterator and associates it with
145 	 * hash_table. Modifying the hash table after calling this function
146 	 * invalidates the returned iterator.
147 	 * $(DDOC_COMMENT example)
148 	 * Since 2.16
149 	 * Params:
150 	 * hashTable = a GHashTable
151 	 */
152 	public void init(HashTable hashTable)
153 	{
154 		// void g_hash_table_iter_init (GHashTableIter *iter,  GHashTable *hash_table);
155 		g_hash_table_iter_init(gHashTableIter, (hashTable is null) ? null : hashTable.getHashTableStruct());
156 	}
157 	
158 	/**
159 	 * Advances iter and retrieves the key and/or value that are now
160 	 * pointed to as a result of this advancement. If FALSE is returned,
161 	 * key and value are not set, and the iterator becomes invalid.
162 	 * Since 2.16
163 	 * Params:
164 	 * key = a location to store the key, or NULL. [allow-none]
165 	 * value = a location to store the value, or NULL. [allow-none]
166 	 * Returns: FALSE if the end of the GHashTable has been reached.
167 	 */
168 	public int next(void** key, void** value)
169 	{
170 		// gboolean g_hash_table_iter_next (GHashTableIter *iter,  gpointer *key,  gpointer *value);
171 		return g_hash_table_iter_next(gHashTableIter, key, value);
172 	}
173 	
174 	/**
175 	 * Returns the GHashTable associated with iter.
176 	 * Since 2.16
177 	 * Returns: the GHashTable associated with iter.
178 	 */
179 	public HashTable getHashTable()
180 	{
181 		// GHashTable * g_hash_table_iter_get_hash_table (GHashTableIter *iter);
182 		auto p = g_hash_table_iter_get_hash_table(gHashTableIter);
183 		
184 		if(p is null)
185 		{
186 			return null;
187 		}
188 		
189 		return new HashTable(cast(GHashTable*) p);
190 	}
191 	
192 	/**
193 	 * Replaces the value currently pointed to by the iterator
194 	 * from its associated GHashTable. Can only be called after
195 	 * g_hash_table_iter_next() returned TRUE.
196 	 * If you supplied a value_destroy_func when creating the
197 	 * GHashTable, the old value is freed using that function.
198 	 * Since 2.30
199 	 * Params:
200 	 * value = the value to replace with
201 	 */
202 	public void replace(void* value)
203 	{
204 		// void g_hash_table_iter_replace (GHashTableIter *iter,  gpointer value);
205 		g_hash_table_iter_replace(gHashTableIter, value);
206 	}
207 	
208 	/**
209 	 * Removes the key/value pair currently pointed to by the iterator
210 	 * from its associated GHashTable. Can only be called after
211 	 * g_hash_table_iter_next() returned TRUE, and cannot be called
212 	 * more than once for the same key/value pair.
213 	 * If the GHashTable was created using g_hash_table_new_full(),
214 	 * the key and value are freed using the supplied destroy functions,
215 	 * otherwise you have to make sure that any dynamically allocated
216 	 * values are freed yourself.
217 	 * Since 2.16
218 	 */
219 	public void remove()
220 	{
221 		// void g_hash_table_iter_remove (GHashTableIter *iter);
222 		g_hash_table_iter_remove(gHashTableIter);
223 	}
224 	
225 	/**
226 	 * Removes the key/value pair currently pointed to by the
227 	 * iterator from its associated GHashTable, without calling
228 	 * the key and value destroy functions. Can only be called
229 	 * after g_hash_table_iter_next() returned TRUE, and cannot
230 	 * be called more than once for the same key/value pair.
231 	 * Since 2.16
232 	 */
233 	public void steal()
234 	{
235 		// void g_hash_table_iter_steal (GHashTableIter *iter);
236 		g_hash_table_iter_steal(gHashTableIter);
237 	}
238 }