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