alternative to assert
[gtkD.git] / src / glib / BBTree.d
blobfb4f4bce703327d6d8fbabff4e509017b7d2df20
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Balanced-Binary-Trees.html
26 * outPack = glib
27 * outFile = BBTree
28 * strct = GTree
29 * realStrct=
30 * ctorStrct=
31 * clss = BBTree
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_tree_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.ListG
45 * - glib.Dataset
46 * structWrap:
47 * - GDataset* -> Dataset
48 * - GList* -> List*
49 * local aliases:
52 module glib.BBTree;
54 private import glib.glibtypes;
56 private import lib.glib;
58 private import glib.ListG;
59 private import glib.Dataset;
61 /**
62 * Description
63 * The GTree structure and its associated functions provide a sorted collection
64 * of key/value pairs optimized for searching and traversing in order.
65 * To create a new GTree use g_tree_new().
66 * To insert a key/value pair into a GTree use g_tree_insert().
67 * To lookup the value corresponding to a given key, use g_tree_lookup() and
68 * g_tree_lookup_extended().
69 * To find out the number of nodes in a GTree, use g_tree_nnodes().
70 * To get the height of a GTree, use g_tree_height().
71 * To traverse a GTree, calling a function for each node visited in the
72 * traversal, use g_tree_foreach().
73 * To remove a key/value pair use g_tree_remove().
74 * To destroy a GTree, use g_tree_destroy().
76 public class BBTree
79 /** the main Gtk struct */
80 protected GTree* gTree;
83 public GTree* getBBTreeStruct()
85 return gTree;
89 /** the main Gtk struct as a void* */
90 protected void* getStruct()
92 return cast(void*)gTree;
95 /**
96 * Sets our main struct and passes it to the parent class
98 public this (GTree* gTree)
100 this.gTree = gTree;
108 * Creates a new GTree.
109 * key_compare_func:
110 * the function used to order the nodes in the GTree.
111 * It should return values similar to the standard strcmp() function -
112 * 0 if the two arguments are equal, a negative value if the first argument
113 * comes before the second, or a positive value if the first argument comes
114 * after the second.
115 * Returns:
116 * a new GTree.
118 public this (GCompareFunc keyCompareFunc)
120 // GTree* g_tree_new (GCompareFunc key_compare_func);
121 this(cast(GTree*)g_tree_new(keyCompareFunc) );
125 * Creates a new GTree with a comparison function that accepts user data.
126 * See g_tree_new() for more details.
127 * key_compare_func:
128 * qsort()-style comparison function.
129 * key_compare_data:
130 * data to pass to comparison function.
131 * Returns:
132 * a new GTree.
134 public this (GCompareDataFunc keyCompareFunc, void* keyCompareData)
136 // GTree* g_tree_new_with_data (GCompareDataFunc key_compare_func, gpointer key_compare_data);
137 this(cast(GTree*)g_tree_new_with_data(keyCompareFunc, keyCompareData) );
141 * Creates a new GTree like g_tree_new() and allows to specify functions
142 * to free the memory allocated for the key and value that get called when
143 * removing the entry from the GTree.
144 * key_compare_func:
145 * qsort()-style comparison function.
146 * key_compare_data:
147 * data to pass to comparison function.
148 * key_destroy_func:
149 * a function to free the memory allocated for the key
150 * used when removing the entry from the GTree or NULL if you don't
151 * want to supply such a function.
152 * value_destroy_func:
153 * a function to free the memory allocated for the
154 * value used when removing the entry from the GTree or NULL if you
155 * don't want to supply such a function.
156 * Returns:
157 * a new GTree.
159 public this (GCompareDataFunc keyCompareFunc, void* keyCompareData, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)
161 // GTree* g_tree_new_full (GCompareDataFunc key_compare_func, gpointer key_compare_data, GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func);
162 this(cast(GTree*)g_tree_new_full(keyCompareFunc, keyCompareData, keyDestroyFunc, valueDestroyFunc) );
166 * Inserts a key/value pair into a GTree. If the given key already exists
167 * in the GTree its corresponding value is set to the new value. If you
168 * supplied a value_destroy_func when creating the GTree, the old value is
169 * freed using that function. If you supplied a key_destroy_func when
170 * creating the GTree, the passed key is freed using that function.
171 * The tree is automatically 'balanced' as new key/value pairs are added,
172 * so that the distance from the root to every leaf is as small as possible.
173 * tree:
174 * a GTree.
175 * key:
176 * the key to insert.
177 * value:
178 * the value corresponding to the key.
180 public void insert(void* key, void* value)
182 // void g_tree_insert (GTree *tree, gpointer key, gpointer value);
183 g_tree_insert(gTree, key, value);
187 * Inserts a new key and value into a GTree similar to g_tree_insert().
188 * The difference is that if the key already exists in the GTree, it gets
189 * replaced by the new key. If you supplied a value_destroy_func when
190 * creating the GTree, the old value is freed using that function. If you
191 * supplied a key_destroy_func when creating the GTree, the old key is
192 * freed using that function.
193 * The tree is automatically 'balanced' as new key/value pairs are added,
194 * so that the distance from the root to every leaf is as small as possible.
195 * tree:
196 * a GTree.
197 * key:
198 * the key to insert.
199 * value:
200 * the value corresponding to the key.
202 public void replace(void* key, void* value)
204 // void g_tree_replace (GTree *tree, gpointer key, gpointer value);
205 g_tree_replace(gTree, key, value);
209 * Gets the number of nodes in a GTree.
210 * tree:
211 * a GTree.
212 * Returns:
213 * the number of nodes in the GTree.
215 public int nnodes()
217 // gint g_tree_nnodes (GTree *tree);
218 return g_tree_nnodes(gTree);
222 * Gets the height of a GTree.
223 * If the GTree contains no nodes, the height is 0.
224 * If the GTree contains only one root node the height is 1.
225 * If the root node has children the height is 2, etc.
226 * tree:
227 * a GTree.
228 * Returns:
229 * the height of the GTree.
231 public int height()
233 // gint g_tree_height (GTree *tree);
234 return g_tree_height(gTree);
238 * Gets the value corresponding to the given key. Since a GTree is
239 * automatically balanced as key/value pairs are added, key lookup is very
240 * fast.
241 * tree:
242 * a GTree.
243 * key:
244 * the key to look up.
245 * Returns:
246 * the value corresponding to the key, or NULL if the key was
247 * not found.
249 public void* lookup(void* key)
251 // gpointer g_tree_lookup (GTree *tree, gconstpointer key);
252 return g_tree_lookup(gTree, key);
256 * Looks up a key in the GTree, returning the original key and the
257 * associated value and a gboolean which is TRUE if the key was found. This
258 * is useful if you need to free the memory allocated for the original key,
259 * for example before calling g_tree_remove().
260 * tree:
261 * a GTree.
262 * lookup_key:
263 * the key to look up.
264 * orig_key:
265 * returns the original key.
266 * value:
267 * returns the value associated with the key.
268 * Returns:
269 * TRUE if the key was found in the GTree.
271 public int lookupExtended(void* lookupKey, void** origKey, void** value)
273 // gboolean g_tree_lookup_extended (GTree *tree, gconstpointer lookup_key, gpointer *orig_key, gpointer *value);
274 return g_tree_lookup_extended(gTree, lookupKey, origKey, value);
278 * Calls the given function for each of the key/value pairs in the GTree.
279 * The function is passed the key and value of each pair, and the given
280 * data parameter. The tree is traversed in sorted order.
281 * The tree may not be modified while iterating over it (you can't
282 * add/remove items). To remove all items matching a predicate, you need
283 * to add each item to a list in your GTraverseFunc as you walk over
284 * the tree, then walk the list and remove each item.
285 * tree:
286 * a GTree.
287 * func:
288 * the function to call for each node visited. If this function
289 * returns TRUE, the traversal is stopped.
290 * user_data:
291 * user data to pass to the function.
293 public void foreac(GTraverseFunc func, void* userData)
295 // void g_tree_foreach (GTree *tree, GTraverseFunc func, gpointer user_data);
296 g_tree_foreach(gTree, func, userData);
300 * Warning
301 * 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
302 * just want to visit all nodes in sorted order, use g_tree_foreach()
303 * instead. If you really need to visit nodes in a different order, consider
304 * using an N-ary Tree.
305 * Calls the given function for each node in the GTree.
306 * tree:
307 * a GTree.
308 * traverse_func:
309 * the function to call for each node visited. If this
310 * function returns TRUE, the traversal is stopped.
311 * traverse_type:
312 * the order in which nodes are visited, one of G_IN_ORDER,
313 * G_PRE_ORDER and G_POST_ORDER.
314 * user_data:
315 * user data to pass to the function.
317 public void traverse(GTraverseFunc traverseFunc, GTraverseType traverseType, void* userData)
319 // void g_tree_traverse (GTree *tree, GTraverseFunc traverse_func, GTraverseType traverse_type, gpointer user_data);
320 g_tree_traverse(gTree, traverseFunc, traverseType, userData);
326 * Searches a GTree using search_func.
327 * The search_func is called with a pointer to the key of a key/value pair in
328 * the tree, and the passed in user_data. If search_func returns 0 for a
329 * key/value pair, then g_tree_search_func() will return the value of that
330 * pair. If search_func returns -1, searching will proceed among the
331 * key/value pairs that have a smaller key; if search_func returns 1,
332 * searching will proceed among the key/value pairs that have a larger key.
333 * tree:
334 * a GTree.
335 * search_func:
336 * a function used to search the GTree.
337 * user_data:
338 * the data passed as the second argument to the search_func
339 * function.
340 * Returns:
341 * the value corresponding to the found key, or NULL if the key
342 * was not found.
344 public void* search(GCompareFunc searchFunc, void* userData)
346 // gpointer g_tree_search (GTree *tree, GCompareFunc search_func, gconstpointer user_data);
347 return g_tree_search(gTree, searchFunc, userData);
351 * Removes a key/value pair from a GTree.
352 * If the GTree was created using g_tree_new_full(), the key and value
353 * are freed using the supplied destroy functions, otherwise you have to
354 * make sure that any dynamically allocated values are freed yourself.
355 * If the key does not exist in the GTree, the function does nothing.
356 * tree:
357 * a GTree.
358 * key:
359 * the key to remove.
360 * Returns:
361 * TRUE if the key was found (prior to 2.8, this function returned
362 * nothing)
364 public int remove(void* key)
366 // gboolean g_tree_remove (GTree *tree, gconstpointer key);
367 return g_tree_remove(gTree, key);
371 * Removes a key and its associated value from a GTree without calling
372 * the key and value destroy functions.
373 * If the key does not exist in the GTree, the function does nothing.
374 * tree:
375 * a GTree.
376 * key:
377 * the key to remove.
378 * Returns:
379 * TRUE if the key was found (prior to 2.8, this function returned
380 * nothing)
382 public int steal(void* key)
384 // gboolean g_tree_steal (GTree *tree, gconstpointer key);
385 return g_tree_steal(gTree, key);
389 * Destroys the GTree. If keys and/or values are dynamically allocated, you
390 * should either free them first or create the GTree using g_tree_new_full().
391 * In the latter case the destroy functions you supplied will be called on
392 * all keys and values before destroying the GTree.
393 * tree:
394 * a GTree.
396 public void destroy()
398 // void g_tree_destroy (GTree *tree);
399 g_tree_destroy(gTree);