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  = glib-Balanced-Binary-Trees.html
27  * outPack = glib
28  * outFile = BBTree
29  * strct   = GTree
30  * realStrct=
31  * ctorStrct=
32  * clss    = BBTree
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_tree_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * 	- GTree* -> BBTree
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.BBTree;
54 
55 public  import gtkc.glibtypes;
56 
57 private import gtkc.glib;
58 private import glib.ConstructionException;
59 
60 
61 
62 
63 
64 
65 /**
66  * Description
67  * The GTree structure and its associated functions provide a sorted
68  * collection of key/value pairs optimized for searching and traversing
69  * in order.
70  * To create a new GTree use g_tree_new().
71  * To insert a key/value pair into a GTree use g_tree_insert().
72  * To lookup the value corresponding to a given key, use
73  * g_tree_lookup() and g_tree_lookup_extended().
74  * To find out the number of nodes in a GTree, use g_tree_nnodes(). To
75  * get the height of a GTree, use g_tree_height().
76  * To traverse a GTree, calling a function for each node visited in
77  * the traversal, use g_tree_foreach().
78  * To remove a key/value pair use g_tree_remove().
79  * To destroy a GTree, use g_tree_destroy().
80  */
81 public class BBTree
82 {
83 	
84 	/** the main Gtk struct */
85 	protected GTree* gTree;
86 	
87 	
88 	public GTree* getBBTreeStruct()
89 	{
90 		return gTree;
91 	}
92 	
93 	
94 	/** the main Gtk struct as a void* */
95 	protected void* getStruct()
96 	{
97 		return cast(void*)gTree;
98 	}
99 	
100 	/**
101 	 * Sets our main struct and passes it to the parent class
102 	 */
103 	public this (GTree* gTree)
104 	{
105 		this.gTree = gTree;
106 	}
107 	
108 	/**
109 	 */
110 	
111 	/**
112 	 * Creates a new GTree.
113 	 * Params:
114 	 * keyCompareFunc = the function used to order the nodes in the GTree.
115 	 * It should return values similar to the standard strcmp() function -
116 	 * 0 if the two arguments are equal, a negative value if the first argument
117 	 * comes before the second, or a positive value if the first argument comes
118 	 * after the second.
119 	 * Throws: ConstructionException GTK+ fails to create the object.
120 	 */
121 	public this (GCompareFunc keyCompareFunc)
122 	{
123 		// GTree * g_tree_new (GCompareFunc key_compare_func);
124 		auto p = g_tree_new(keyCompareFunc);
125 		if(p is null)
126 		{
127 			throw new ConstructionException("null returned by g_tree_new(keyCompareFunc)");
128 		}
129 		this(cast(GTree*) p);
130 	}
131 	
132 	/**
133 	 * Increments the reference count of tree by one. It is safe to call
134 	 * this function from any thread.
135 	 * Since 2.22
136 	 * Returns: the passed in GTree.
137 	 */
138 	public BBTree doref()
139 	{
140 		// GTree * g_tree_ref (GTree *tree);
141 		auto p = g_tree_ref(gTree);
142 		
143 		if(p is null)
144 		{
145 			return null;
146 		}
147 		
148 		return new BBTree(cast(GTree*) p);
149 	}
150 	
151 	/**
152 	 * Decrements the reference count of tree by one. If the reference count
153 	 * drops to 0, all keys and values will be destroyed (if destroy
154 	 * functions were specified) and all memory allocated by tree will be
155 	 * released.
156 	 * It is safe to call this function from any thread.
157 	 * Since 2.22
158 	 */
159 	public void unref()
160 	{
161 		// void g_tree_unref (GTree *tree);
162 		g_tree_unref(gTree);
163 	}
164 	
165 	/**
166 	 * Creates a new GTree with a comparison function that accepts user data.
167 	 * See g_tree_new() for more details.
168 	 * Params:
169 	 * keyCompareFunc = qsort()-style comparison function.
170 	 * keyCompareData = data to pass to comparison function.
171 	 * Throws: ConstructionException GTK+ fails to create the object.
172 	 */
173 	public this (GCompareDataFunc keyCompareFunc, void* keyCompareData)
174 	{
175 		// GTree * g_tree_new_with_data (GCompareDataFunc key_compare_func,  gpointer key_compare_data);
176 		auto p = g_tree_new_with_data(keyCompareFunc, keyCompareData);
177 		if(p is null)
178 		{
179 			throw new ConstructionException("null returned by g_tree_new_with_data(keyCompareFunc, keyCompareData)");
180 		}
181 		this(cast(GTree*) p);
182 	}
183 	
184 	/**
185 	 * Creates a new GTree like g_tree_new() and allows to specify functions
186 	 * to free the memory allocated for the key and value that get called when
187 	 * removing the entry from the GTree.
188 	 * Params:
189 	 * keyCompareFunc = qsort()-style comparison function.
190 	 * keyCompareData = data to pass to comparison function.
191 	 * keyDestroyFunc = a function to free the memory allocated for the key
192 	 * used when removing the entry from the GTree or NULL if you don't
193 	 * want to supply such a function.
194 	 * valueDestroyFunc = a function to free the memory allocated for the
195 	 * value used when removing the entry from the GTree or NULL if you
196 	 * don't want to supply such a function.
197 	 * Throws: ConstructionException GTK+ fails to create the object.
198 	 */
199 	public this (GCompareDataFunc keyCompareFunc, void* keyCompareData, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)
200 	{
201 		// GTree * g_tree_new_full (GCompareDataFunc key_compare_func,  gpointer key_compare_data,  GDestroyNotify key_destroy_func,  GDestroyNotify value_destroy_func);
202 		auto p = g_tree_new_full(keyCompareFunc, keyCompareData, keyDestroyFunc, valueDestroyFunc);
203 		if(p is null)
204 		{
205 			throw new ConstructionException("null returned by g_tree_new_full(keyCompareFunc, keyCompareData, keyDestroyFunc, valueDestroyFunc)");
206 		}
207 		this(cast(GTree*) p);
208 	}
209 	
210 	/**
211 	 * Inserts a key/value pair into a GTree. If the given key already exists
212 	 * in the GTree its corresponding value is set to the new value. If you
213 	 * supplied a value_destroy_func when creating the GTree, the old value is
214 	 * freed using that function. If you supplied a key_destroy_func when
215 	 * creating the GTree, the passed key is freed using that function.
216 	 * The tree is automatically 'balanced' as new key/value pairs are added,
217 	 * so that the distance from the root to every leaf is as small as possible.
218 	 * Params:
219 	 * key = the key to insert.
220 	 * value = the value corresponding to the key.
221 	 */
222 	public void insert(void* key, void* value)
223 	{
224 		// void g_tree_insert (GTree *tree,  gpointer key,  gpointer value);
225 		g_tree_insert(gTree, key, value);
226 	}
227 	
228 	/**
229 	 * Inserts a new key and value into a GTree similar to g_tree_insert().
230 	 * The difference is that if the key already exists in the GTree, it gets
231 	 * replaced by the new key. If you supplied a value_destroy_func when
232 	 * creating the GTree, the old value is freed using that function. If you
233 	 * supplied a key_destroy_func when creating the GTree, the old key is
234 	 * freed using that function.
235 	 * The tree is automatically 'balanced' as new key/value pairs are added,
236 	 * so that the distance from the root to every leaf is as small as possible.
237 	 * Params:
238 	 * key = the key to insert.
239 	 * value = the value corresponding to the key.
240 	 */
241 	public void replace(void* key, void* value)
242 	{
243 		// void g_tree_replace (GTree *tree,  gpointer key,  gpointer value);
244 		g_tree_replace(gTree, key, value);
245 	}
246 	
247 	/**
248 	 * Gets the number of nodes in a GTree.
249 	 * Returns: the number of nodes in the GTree.
250 	 */
251 	public int nnodes()
252 	{
253 		// gint g_tree_nnodes (GTree *tree);
254 		return g_tree_nnodes(gTree);
255 	}
256 	
257 	/**
258 	 * Gets the height of a GTree.
259 	 * If the GTree contains no nodes, the height is 0.
260 	 * If the GTree contains only one root node the height is 1.
261 	 * If the root node has children the height is 2, etc.
262 	 * Returns: the height of the GTree.
263 	 */
264 	public int height()
265 	{
266 		// gint g_tree_height (GTree *tree);
267 		return g_tree_height(gTree);
268 	}
269 	
270 	/**
271 	 * Gets the value corresponding to the given key. Since a GTree is
272 	 * automatically balanced as key/value pairs are added, key lookup is very
273 	 * fast.
274 	 * Params:
275 	 * key = the key to look up.
276 	 * Returns: the value corresponding to the key, or NULL if the key was not found.
277 	 */
278 	public void* lookup(void* key)
279 	{
280 		// gpointer g_tree_lookup (GTree *tree,  gconstpointer key);
281 		return g_tree_lookup(gTree, key);
282 	}
283 	
284 	/**
285 	 * Looks up a key in the GTree, returning the original key and the
286 	 * associated value and a gboolean which is TRUE if the key was found. This
287 	 * is useful if you need to free the memory allocated for the original key,
288 	 * for example before calling g_tree_remove().
289 	 * Params:
290 	 * lookupKey = the key to look up.
291 	 * origKey = returns the original key.
292 	 * value = returns the value associated with the key.
293 	 * Returns: TRUE if the key was found in the GTree.
294 	 */
295 	public int lookupExtended(void* lookupKey, void** origKey, void** value)
296 	{
297 		// gboolean g_tree_lookup_extended (GTree *tree,  gconstpointer lookup_key,  gpointer *orig_key,  gpointer *value);
298 		return g_tree_lookup_extended(gTree, lookupKey, origKey, value);
299 	}
300 	
301 	/**
302 	 * Calls the given function for each of the key/value pairs in the GTree.
303 	 * The function is passed the key and value of each pair, and the given
304 	 * data parameter. The tree is traversed in sorted order.
305 	 * The tree may not be modified while iterating over it (you can't
306 	 * add/remove items). To remove all items matching a predicate, you need
307 	 * to add each item to a list in your GTraverseFunc as you walk over
308 	 * the tree, then walk the list and remove each item.
309 	 * Params:
310 	 * func = the function to call for each node visited. If this function
311 	 * returns TRUE, the traversal is stopped.
312 	 * userData = user data to pass to the function.
313 	 */
314 	public void foreac(GTraverseFunc func, void* userData)
315 	{
316 		// void g_tree_foreach (GTree *tree,  GTraverseFunc func,  gpointer user_data);
317 		g_tree_foreach(gTree, func, userData);
318 	}
319 	
320 	/**
321 	 * Warning
322 	 * g_tree_traverse has been deprecated since version 2.2 and should not be used in newly-written code. The order of a balanced tree is somewhat arbitrary. If you
323 	 * just want to visit all nodes in sorted order, use g_tree_foreach()
324 	 * instead. If you really need to visit nodes in a different order, consider
325 	 * using an N-ary Tree.
326 	 * Calls the given function for each node in the GTree.
327 	 * Params:
328 	 * traverseFunc = the function to call for each node visited. If this
329 	 * function returns TRUE, the traversal is stopped.
330 	 * traverseType = the order in which nodes are visited, one of G_IN_ORDER,
331 	 * G_PRE_ORDER and G_POST_ORDER.
332 	 * userData = user data to pass to the function.
333 	 */
334 	public void traverse(GTraverseFunc traverseFunc, GTraverseType traverseType, void* userData)
335 	{
336 		// void g_tree_traverse (GTree *tree,  GTraverseFunc traverse_func,  GTraverseType traverse_type,  gpointer user_data);
337 		g_tree_traverse(gTree, traverseFunc, traverseType, userData);
338 	}
339 	
340 	/**
341 	 * Searches a GTree using search_func.
342 	 * The search_func is called with a pointer to the key of a key/value pair in
343 	 * the tree, and the passed in user_data. If search_func returns 0 for a
344 	 * key/value pair, then g_tree_search_func() will return the value of that
345 	 * pair. If search_func returns -1, searching will proceed among the
346 	 * key/value pairs that have a smaller key; if search_func returns 1,
347 	 * searching will proceed among the key/value pairs that have a larger key.
348 	 * Params:
349 	 * searchFunc = a function used to search the GTree.
350 	 * userData = the data passed as the second argument to the search_func
351 	 * function.
352 	 * Returns: the value corresponding to the found key, or NULL if the key was not found.
353 	 */
354 	public void* search(GCompareFunc searchFunc, void* userData)
355 	{
356 		// gpointer g_tree_search (GTree *tree,  GCompareFunc search_func,  gconstpointer user_data);
357 		return g_tree_search(gTree, searchFunc, userData);
358 	}
359 	
360 	/**
361 	 * Removes a key/value pair from a GTree.
362 	 * If the GTree was created using g_tree_new_full(), the key and value
363 	 * are freed using the supplied destroy functions, otherwise you have to
364 	 * make sure that any dynamically allocated values are freed yourself.
365 	 * If the key does not exist in the GTree, the function does nothing.
366 	 * Params:
367 	 * key = the key to remove.
368 	 * Returns: TRUE if the key was found (prior to 2.8, this function returned nothing)
369 	 */
370 	public int remove(void* key)
371 	{
372 		// gboolean g_tree_remove (GTree *tree,  gconstpointer key);
373 		return g_tree_remove(gTree, key);
374 	}
375 	
376 	/**
377 	 * Removes a key and its associated value from a GTree without calling
378 	 * the key and value destroy functions.
379 	 * If the key does not exist in the GTree, the function does nothing.
380 	 * Params:
381 	 * key = the key to remove.
382 	 * Returns: TRUE if the key was found (prior to 2.8, this function returned nothing)
383 	 */
384 	public int steal(void* key)
385 	{
386 		// gboolean g_tree_steal (GTree *tree,  gconstpointer key);
387 		return g_tree_steal(gTree, key);
388 	}
389 	
390 	/**
391 	 * Removes all keys and values from the GTree and decreases its
392 	 * reference count by one. If keys and/or values are dynamically
393 	 * allocated, you should either free them first or create the GTree
394 	 * using g_tree_new_full(). In the latter case the destroy functions
395 	 * you supplied will be called on all keys and values before destroying
396 	 * the GTree.
397 	 */
398 	public void destroy()
399 	{
400 		// void g_tree_destroy (GTree *tree);
401 		g_tree_destroy(gTree);
402 	}
403 }