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-N-ary-Trees.html
27  * outPack = glib
28  * outFile = Node
29  * strct   = GNode
30  * realStrct=
31  * ctorStrct=
32  * clss    = Node
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_node_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * structWrap:
47  * 	- GNode* -> Node
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.Node;
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 GNode struct and its associated functions provide a N-ary tree
68  * data structure, where nodes in the tree can contain arbitrary data.
69  * To create a new tree use g_node_new().
70  * To insert a node into a tree use g_node_insert(),
71  * g_node_insert_before(), g_node_append() and g_node_prepend().
72  * To create a new node and insert it into a tree use
73  * g_node_insert_data(), g_node_insert_data_before(),
74  * g_node_append_data() and g_node_prepend_data().
75  * To reverse the children of a node use g_node_reverse_children().
76  * To find a node use g_node_get_root(), g_node_find(),
77  * g_node_find_child(), g_node_child_index(), g_node_child_position(),
78  * g_node_first_child(), g_node_last_child(), g_node_nth_child(),
79  * g_node_first_sibling(), g_node_prev_sibling(), g_node_next_sibling()
80  * or g_node_last_sibling().
81  * To get information about a node or tree use G_NODE_IS_LEAF(),
82  * G_NODE_IS_ROOT(), g_node_depth(), g_node_n_nodes(),
83  * g_node_n_children(), g_node_is_ancestor() or g_node_max_height().
84  * To traverse a tree, calling a function for each node visited in the
85  * traversal, use g_node_traverse() or g_node_children_foreach().
86  * To remove a node or subtree from a tree use g_node_unlink() or
87  * g_node_destroy().
88  */
89 public class Node
90 {
91 	
92 	/** the main Gtk struct */
93 	protected GNode* gNode;
94 	
95 	
96 	public GNode* getNodeStruct()
97 	{
98 		return gNode;
99 	}
100 	
101 	
102 	/** the main Gtk struct as a void* */
103 	protected void* getStruct()
104 	{
105 		return cast(void*)gNode;
106 	}
107 	
108 	/**
109 	 * Sets our main struct and passes it to the parent class
110 	 */
111 	public this (GNode* gNode)
112 	{
113 		this.gNode = gNode;
114 	}
115 	
116 	/**
117 	 */
118 	
119 	/**
120 	 * Creates a new GNode containing the given data.
121 	 * Used to create the first node in a tree.
122 	 * Params:
123 	 * data = the data of the new node
124 	 * Throws: ConstructionException GTK+ fails to create the object.
125 	 */
126 	public this (void* data)
127 	{
128 		// GNode *	 g_node_new (gpointer data);
129 		auto p = g_node_new(data);
130 		if(p is null)
131 		{
132 			throw new ConstructionException("null returned by g_node_new(data)");
133 		}
134 		this(cast(GNode*) p);
135 	}
136 	
137 	/**
138 	 * Recursively copies a GNode (but does not deep-copy the data inside the
139 	 * nodes, see g_node_copy_deep() if you need that).
140 	 * Returns: a new GNode containing the same data pointers
141 	 */
142 	public Node copy()
143 	{
144 		// GNode * g_node_copy (GNode *node);
145 		auto p = g_node_copy(gNode);
146 		
147 		if(p is null)
148 		{
149 			return null;
150 		}
151 		
152 		return new Node(cast(GNode*) p);
153 	}
154 	
155 	/**
156 	 * Recursively copies a GNode and its data.
157 	 * Since 2.4
158 	 * Params:
159 	 * copyFunc = the function which is called to copy the data inside each node,
160 	 * or NULL to use the original data.
161 	 * data = data to pass to copy_func
162 	 * Returns: a new GNode containing copies of the data in node.
163 	 */
164 	public Node copyDeep(GCopyFunc copyFunc, void* data)
165 	{
166 		// GNode * g_node_copy_deep (GNode *node,  GCopyFunc copy_func,  gpointer data);
167 		auto p = g_node_copy_deep(gNode, copyFunc, data);
168 		
169 		if(p is null)
170 		{
171 			return null;
172 		}
173 		
174 		return new Node(cast(GNode*) p);
175 	}
176 	
177 	/**
178 	 * Inserts a GNode beneath the parent at the given position.
179 	 * Params:
180 	 * position = the position to place node at, with respect to its siblings
181 	 * If position is -1, node is inserted as the last child of parent
182 	 * node = the GNode to insert
183 	 * Returns: the inserted GNode
184 	 */
185 	public Node insert(int position, Node node)
186 	{
187 		// GNode *	 g_node_insert (GNode *parent,  gint position,  GNode *node);
188 		auto p = g_node_insert(gNode, position, (node is null) ? null : node.getNodeStruct());
189 		
190 		if(p is null)
191 		{
192 			return null;
193 		}
194 		
195 		return new Node(cast(GNode*) p);
196 	}
197 	
198 	/**
199 	 * Inserts a GNode beneath the parent before the given sibling.
200 	 * Params:
201 	 * sibling = the sibling GNode to place node before.
202 	 * If sibling is NULL, the node is inserted as the last child of parent.
203 	 * node = the GNode to insert
204 	 * Returns: the inserted GNode
205 	 */
206 	public Node insertBefore(Node sibling, Node node)
207 	{
208 		// GNode *	 g_node_insert_before (GNode *parent,  GNode *sibling,  GNode *node);
209 		auto p = g_node_insert_before(gNode, (sibling is null) ? null : sibling.getNodeStruct(), (node is null) ? null : node.getNodeStruct());
210 		
211 		if(p is null)
212 		{
213 			return null;
214 		}
215 		
216 		return new Node(cast(GNode*) p);
217 	}
218 	
219 	/**
220 	 * Inserts a GNode beneath the parent after the given sibling.
221 	 * Params:
222 	 * sibling = the sibling GNode to place node after.
223 	 * If sibling is NULL, the node is inserted as the first child of parent.
224 	 * node = the GNode to insert
225 	 * Returns: the inserted GNode
226 	 */
227 	public Node insertAfter(Node sibling, Node node)
228 	{
229 		// GNode * g_node_insert_after (GNode *parent,  GNode *sibling,  GNode *node);
230 		auto p = g_node_insert_after(gNode, (sibling is null) ? null : sibling.getNodeStruct(), (node is null) ? null : node.getNodeStruct());
231 		
232 		if(p is null)
233 		{
234 			return null;
235 		}
236 		
237 		return new Node(cast(GNode*) p);
238 	}
239 	
240 	/**
241 	 * Inserts a GNode as the first child of the given parent.
242 	 * Params:
243 	 * node = the GNode to insert
244 	 * Returns: the inserted GNode
245 	 */
246 	public Node prepend(Node node)
247 	{
248 		// GNode *	 g_node_prepend (GNode *parent,  GNode *node);
249 		auto p = g_node_prepend(gNode, (node is null) ? null : node.getNodeStruct());
250 		
251 		if(p is null)
252 		{
253 			return null;
254 		}
255 		
256 		return new Node(cast(GNode*) p);
257 	}
258 	
259 	/**
260 	 * Reverses the order of the children of a GNode.
261 	 * (It doesn't change the order of the grandchildren.)
262 	 */
263 	public void reverseChildren()
264 	{
265 		// void g_node_reverse_children (GNode *node);
266 		g_node_reverse_children(gNode);
267 	}
268 	
269 	/**
270 	 * Traverses a tree starting at the given root GNode.
271 	 * It calls the given function for each node visited.
272 	 * The traversal can be halted at any point by returning TRUE from func.
273 	 * Params:
274 	 * order = the order in which nodes are visited - G_IN_ORDER,
275 	 * G_PRE_ORDER, G_POST_ORDER, or G_LEVEL_ORDER.
276 	 * flags = which types of children are to be visited, one of
277 	 * G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES
278 	 * maxDepth = the maximum depth of the traversal. Nodes below this
279 	 * depth will not be visited. If max_depth is -1 all nodes in
280 	 * the tree are visited. If depth is 1, only the root is visited.
281 	 * If depth is 2, the root and its children are visited. And so on.
282 	 * func = the function to call for each visited GNode
283 	 * data = user data to pass to the function
284 	 */
285 	public void traverse(GTraverseType order, GTraverseFlags flags, int maxDepth, GNodeTraverseFunc func, void* data)
286 	{
287 		// void g_node_traverse (GNode *root,  GTraverseType order,  GTraverseFlags flags,  gint max_depth,  GNodeTraverseFunc func,  gpointer data);
288 		g_node_traverse(gNode, order, flags, maxDepth, func, data);
289 	}
290 	
291 	/**
292 	 * Calls a function for each of the children of a GNode.
293 	 * Note that it doesn't descend beneath the child nodes.
294 	 * Params:
295 	 * flags = which types of children are to be visited, one of
296 	 * G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES
297 	 * func = the function to call for each visited node
298 	 * data = user data to pass to the function
299 	 */
300 	public void childrenForeach(GTraverseFlags flags, GNodeForeachFunc func, void* data)
301 	{
302 		// void g_node_children_foreach (GNode *node,  GTraverseFlags flags,  GNodeForeachFunc func,  gpointer data);
303 		g_node_children_foreach(gNode, flags, func, data);
304 	}
305 	
306 	/**
307 	 * Gets the root of a tree.
308 	 * Returns: the root of the tree
309 	 */
310 	public Node getRoot()
311 	{
312 		// GNode *	 g_node_get_root (GNode *node);
313 		auto p = g_node_get_root(gNode);
314 		
315 		if(p is null)
316 		{
317 			return null;
318 		}
319 		
320 		return new Node(cast(GNode*) p);
321 	}
322 	
323 	/**
324 	 * Finds a GNode in a tree.
325 	 * Params:
326 	 * order = the order in which nodes are visited - G_IN_ORDER,
327 	 * G_PRE_ORDER, G_POST_ORDER, or G_LEVEL_ORDER
328 	 * flags = which types of children are to be searched, one of
329 	 * G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES
330 	 * data = the data to find
331 	 * Returns: the found GNode, or NULL if the data is not found
332 	 */
333 	public Node find(GTraverseType order, GTraverseFlags flags, void* data)
334 	{
335 		// GNode *	 g_node_find (GNode *root,  GTraverseType order,  GTraverseFlags flags,  gpointer data);
336 		auto p = g_node_find(gNode, order, flags, data);
337 		
338 		if(p is null)
339 		{
340 			return null;
341 		}
342 		
343 		return new Node(cast(GNode*) p);
344 	}
345 	
346 	/**
347 	 * Finds the first child of a GNode with the given data.
348 	 * Params:
349 	 * flags = which types of children are to be searched, one of
350 	 * G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES
351 	 * data = the data to find
352 	 * Returns: the found child GNode, or NULL if the data is not found
353 	 */
354 	public Node findChild(GTraverseFlags flags, void* data)
355 	{
356 		// GNode *	 g_node_find_child (GNode *node,  GTraverseFlags flags,  gpointer data);
357 		auto p = g_node_find_child(gNode, flags, data);
358 		
359 		if(p is null)
360 		{
361 			return null;
362 		}
363 		
364 		return new Node(cast(GNode*) p);
365 	}
366 	
367 	/**
368 	 * Gets the position of the first child of a GNode
369 	 * which contains the given data.
370 	 * Params:
371 	 * data = the data to find
372 	 * Returns: the index of the child of node which contains data, or -1 if the data is not found
373 	 */
374 	public int childIndex(void* data)
375 	{
376 		// gint g_node_child_index (GNode *node,  gpointer data);
377 		return g_node_child_index(gNode, data);
378 	}
379 	
380 	/**
381 	 * Gets the position of a GNode with respect to its siblings.
382 	 * child must be a child of node. The first child is numbered 0,
383 	 * the second 1, and so on.
384 	 * Params:
385 	 * child = a child of node
386 	 * Returns: the position of child with respect to its siblings
387 	 */
388 	public int childPosition(Node child)
389 	{
390 		// gint g_node_child_position (GNode *node,  GNode *child);
391 		return g_node_child_position(gNode, (child is null) ? null : child.getNodeStruct());
392 	}
393 	
394 	/**
395 	 * Gets the last child of a GNode.
396 	 * Returns: the last child of node, or NULL if node has no children
397 	 */
398 	public Node lastChild()
399 	{
400 		// GNode *	 g_node_last_child (GNode *node);
401 		auto p = g_node_last_child(gNode);
402 		
403 		if(p is null)
404 		{
405 			return null;
406 		}
407 		
408 		return new Node(cast(GNode*) p);
409 	}
410 	
411 	/**
412 	 * Gets a child of a GNode, using the given index.
413 	 * The first child is at index 0. If the index is
414 	 * too big, NULL is returned.
415 	 * Params:
416 	 * n = the index of the desired child
417 	 * Returns: the child of node at index n
418 	 */
419 	public Node nthChild(uint n)
420 	{
421 		// GNode *	 g_node_nth_child (GNode *node,  guint n);
422 		auto p = g_node_nth_child(gNode, n);
423 		
424 		if(p is null)
425 		{
426 			return null;
427 		}
428 		
429 		return new Node(cast(GNode*) p);
430 	}
431 	
432 	/**
433 	 * Gets the first sibling of a GNode.
434 	 * This could possibly be the node itself.
435 	 * Returns: the first sibling of node
436 	 */
437 	public Node firstSibling()
438 	{
439 		// GNode *	 g_node_first_sibling (GNode *node);
440 		auto p = g_node_first_sibling(gNode);
441 		
442 		if(p is null)
443 		{
444 			return null;
445 		}
446 		
447 		return new Node(cast(GNode*) p);
448 	}
449 	
450 	/**
451 	 * Gets the last sibling of a GNode.
452 	 * This could possibly be the node itself.
453 	 * Returns: the last sibling of node
454 	 */
455 	public Node lastSibling()
456 	{
457 		// GNode *	 g_node_last_sibling (GNode *node);
458 		auto p = g_node_last_sibling(gNode);
459 		
460 		if(p is null)
461 		{
462 			return null;
463 		}
464 		
465 		return new Node(cast(GNode*) p);
466 	}
467 	
468 	/**
469 	 * Gets the depth of a GNode.
470 	 * If node is NULL the depth is 0. The root node has a depth of 1.
471 	 * For the children of the root node the depth is 2. And so on.
472 	 * Returns: the depth of the GNode
473 	 */
474 	public uint depth()
475 	{
476 		// guint g_node_depth (GNode *node);
477 		return g_node_depth(gNode);
478 	}
479 	
480 	/**
481 	 * Gets the number of nodes in a tree.
482 	 * Params:
483 	 * flags = which types of children are to be counted, one of
484 	 * G_TRAVERSE_ALL, G_TRAVERSE_LEAVES and G_TRAVERSE_NON_LEAVES
485 	 * Returns: the number of nodes in the tree
486 	 */
487 	public uint nNodes(GTraverseFlags flags)
488 	{
489 		// guint g_node_n_nodes (GNode *root,  GTraverseFlags flags);
490 		return g_node_n_nodes(gNode, flags);
491 	}
492 	
493 	/**
494 	 * Gets the number of children of a GNode.
495 	 * Returns: the number of children of node
496 	 */
497 	public uint nChildren()
498 	{
499 		// guint g_node_n_children (GNode *node);
500 		return g_node_n_children(gNode);
501 	}
502 	
503 	/**
504 	 * Returns TRUE if node is an ancestor of descendant.
505 	 * This is true if node is the parent of descendant,
506 	 * or if node is the grandparent of descendant etc.
507 	 * Params:
508 	 * descendant = a GNode
509 	 * Returns: TRUE if node is an ancestor of descendant
510 	 */
511 	public int isAncestor(Node descendant)
512 	{
513 		// gboolean g_node_is_ancestor (GNode *node,  GNode *descendant);
514 		return g_node_is_ancestor(gNode, (descendant is null) ? null : descendant.getNodeStruct());
515 	}
516 	
517 	/**
518 	 * Gets the maximum height of all branches beneath a GNode.
519 	 * This is the maximum distance from the GNode to all leaf nodes.
520 	 * If root is NULL, 0 is returned. If root has no children,
521 	 * 1 is returned. If root has children, 2 is returned. And so on.
522 	 * Returns: the maximum height of the tree beneath root
523 	 */
524 	public uint maxHeight()
525 	{
526 		// guint g_node_max_height (GNode *root);
527 		return g_node_max_height(gNode);
528 	}
529 	
530 	/**
531 	 * Unlinks a GNode from a tree, resulting in two separate trees.
532 	 */
533 	public void unlink()
534 	{
535 		// void g_node_unlink (GNode *node);
536 		g_node_unlink(gNode);
537 	}
538 	
539 	/**
540 	 * Removes root and its children from the tree, freeing any memory
541 	 * allocated.
542 	 */
543 	public void destroy()
544 	{
545 		// void g_node_destroy (GNode *root);
546 		g_node_destroy(gNode);
547 	}
548 	
549 	/**
550 	 * Warning
551 	 * g_node_push_allocator has been deprecated since version 2.10 and should not be used in newly-written code. It does nothing, since GNode has been converted to
552 	 *  the slice
553 	 *  allocator
554 	 * Sets the allocator to use to allocate GNode elements. Use
555 	 * g_node_pop_allocator() to restore the previous allocator.
556 	 * Note that this function is not available if GLib has been compiled
557 	 * with --disable-mem-pools
558 	 * Params:
559 	 * dummy = the GAllocator to use when allocating GNode elements.
560 	 */
561 	public static void pushAllocator(void* dummy)
562 	{
563 		// void g_node_push_allocator (gpointer dummy);
564 		g_node_push_allocator(dummy);
565 	}
566 	
567 	/**
568 	 * Warning
569 	 * g_node_pop_allocator has been deprecated since version 2.10 and should not be used in newly-written code. It does nothing, since GNode has been converted to
570 	 *  the slice
571 	 *  allocator
572 	 * Restores the previous GAllocator, used when allocating GNode
573 	 * elements.
574 	 * Note that this function is not available if GLib has been compiled
575 	 * with --disable-mem-pools
576 	 */
577 	public static void popAllocator()
578 	{
579 		// void g_node_pop_allocator (void);
580 		g_node_pop_allocator();
581 	}
582 }