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