+Sun Feb 22 00:47:04 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gnode.c (g_node_copy_deep): New function to deep-copy a
+ GNode and its children. (#93464, James M. Cape)
+
Sat Feb 21 15:42:39 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* glib/gqueue.c: Some documentation fixes.
+Sun Feb 22 00:47:04 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gnode.c (g_node_copy_deep): New function to deep-copy a
+ GNode and its children. (#93464, James M. Cape)
+
Sat Feb 21 15:42:39 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* glib/gqueue.c: Some documentation fixes.
+Sun Feb 22 00:47:04 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gnode.c (g_node_copy_deep): New function to deep-copy a
+ GNode and its children. (#93464, James M. Cape)
+
Sat Feb 21 15:42:39 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* glib/gqueue.c: Some documentation fixes.
+Sun Feb 22 00:47:04 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gnode.c (g_node_copy_deep): New function to deep-copy a
+ GNode and its children. (#93464, James M. Cape)
+
Sat Feb 21 15:42:39 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* glib/gqueue.c: Some documentation fixes.
+Sun Feb 22 00:47:04 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gnode.c (g_node_copy_deep): New function to deep-copy a
+ GNode and its children. (#93464, James M. Cape)
+
Sat Feb 21 15:42:39 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* glib/gqueue.c: Some documentation fixes.
+Sun Feb 22 00:47:04 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gnode.c (g_node_copy_deep): New function to deep-copy a
+ GNode and its children. (#93464, James M. Cape)
+
Sat Feb 21 15:42:39 2004 Soeren Sandmann <sandmann@daimi.au.dk>
* glib/gqueue.c: Some documentation fixes.
+Sun Feb 22 00:59:11 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/tmpl/trees-nary.sgml: Document GCopyFunc.
+
+Sun Feb 22 00:54:17 2004 Matthias Clasen <maclas@gmx.de>
+
+ * glib/glib-sections.txt: Add GCopyFunc and g_node_copy_deep.
+
2004-02-18 Sebastian Wilhelmi <seppi@seppi.de>
* glib/glib-sections.txt: Add the new g_rand_* functions
GNode
g_node_new
g_node_copy
+GCopyFunc
+g_node_copy_deep
<SUBSECTION>
g_node_insert
<!-- ##### FUNCTION g_node_copy ##### -->
<para>
Recursively copies a #GNode (but does not deep-copy the data inside the nodes,
-since there's no way for GLib to know how to do that).
+see g_node_copy_deep() if you need that).
</para>
@node: a #GNode.
@Returns: a new #GNode containing the same data pointers.
+<!-- ##### USER_FUNCTION GCopyFunc ##### -->
+<para>
+A function of this signature is used to copy the node data when doing a deep-copy
+of a tree.
+</para>
+
+@src: A pointer to the data which should be copied.
+@data: Additional data.
+@Returns: A pointer to the copy.
+@Since: 2.4
+
+<!-- ##### FUNCTION g_node_copy_deep ##### -->
+<para>
+
+</para>
+
+@node:
+@copy_func:
+@data:
+@Returns:
+
+
<!-- ##### FUNCTION g_node_insert ##### -->
<para>
Inserts a #GNode beneath the parent at the given position.
node->prev = NULL;
}
+/**
+ * g_node_copy_deep:
+ * @node: a #GNode
+ * @copy_func: the function which is called to copy the data inside each node,
+ * or %NULL to use the original data.
+ * @data: data to pass to @copy_func
+ *
+ * Recursively copies a #GNode and its data.
+ *
+ * Return value: a new #GNode containing copies of the data in @node.
+ *
+ * Since: 2.4
+ **/
+GNode*
+g_node_copy_deep (GNode *node,
+ GCopyFunc copy_func,
+ gpointer data)
+{
+ GNode *new_node = NULL;
+
+ if (copy_func == NULL)
+ return g_node_copy (node);
+
+ if (node)
+ {
+ GNode *child, *new_child;
+
+ new_node = g_node_new (copy_func (node->data, data));
+
+ for (child = g_node_last_child (node); child; child = child->prev)
+ {
+ new_child = g_node_copy_deep (child, copy_func, data);
+ g_node_prepend (new_node, new_child);
+ }
+ }
+
+ return new_node;
+}
+
GNode*
g_node_copy (GNode *node)
{
gpointer data);
typedef void (*GNodeForeachFunc) (GNode *node,
gpointer data);
+typedef gpointer (*GCopyFunc) (gconstpointer src,
+ gpointer data);
/* N-way tree implementation
*/
GNode* g_node_new (gpointer data);
void g_node_destroy (GNode *root);
void g_node_unlink (GNode *node);
+GNode* g_node_copy_deep (GNode *node,
+ GCopyFunc copy_func,
+ gpointer data);
GNode* g_node_copy (GNode *node);
GNode* g_node_insert (GNode *parent,
gint position,