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