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