diff --git a/ChangeLog b/ChangeLog index 15e4d0173..5dcb47184 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Feb 22 00:47:04 2004 Matthias Clasen + + * 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 * glib/gqueue.c: Some documentation fixes. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 15e4d0173..5dcb47184 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +Sun Feb 22 00:47:04 2004 Matthias Clasen + + * 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 * glib/gqueue.c: Some documentation fixes. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 15e4d0173..5dcb47184 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +Sun Feb 22 00:47:04 2004 Matthias Clasen + + * 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 * glib/gqueue.c: Some documentation fixes. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 15e4d0173..5dcb47184 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,8 @@ +Sun Feb 22 00:47:04 2004 Matthias Clasen + + * 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 * glib/gqueue.c: Some documentation fixes. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 15e4d0173..5dcb47184 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,8 @@ +Sun Feb 22 00:47:04 2004 Matthias Clasen + + * 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 * glib/gqueue.c: Some documentation fixes. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 15e4d0173..5dcb47184 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +Sun Feb 22 00:47:04 2004 Matthias Clasen + + * 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 * glib/gqueue.c: Some documentation fixes. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 8c77846e4..ede56c546 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,11 @@ +Sun Feb 22 00:59:11 2004 Matthias Clasen + + * glib/tmpl/trees-nary.sgml: Document GCopyFunc. + +Sun Feb 22 00:54:17 2004 Matthias Clasen + + * glib/glib-sections.txt: Add GCopyFunc and g_node_copy_deep. + 2004-02-18 Sebastian Wilhelmi * glib/glib-sections.txt: Add the new g_rand_* functions diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index c07a21856..157c92a60 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -1699,6 +1699,8 @@ g_tree_destroy GNode g_node_new g_node_copy +GCopyFunc +g_node_copy_deep g_node_insert diff --git a/docs/reference/glib/tmpl/trees-nary.sgml b/docs/reference/glib/tmpl/trees-nary.sgml index 9cd1767a0..d4326da75 100644 --- a/docs/reference/glib/tmpl/trees-nary.sgml +++ b/docs/reference/glib/tmpl/trees-nary.sgml @@ -83,13 +83,35 @@ Used to create the first node in a tree. 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). @node: a #GNode. @Returns: a new #GNode containing the same data pointers. + + +A function of this signature is used to copy the node data when doing a deep-copy +of a tree. + + +@src: A pointer to the data which should be copied. +@data: Additional data. +@Returns: A pointer to the copy. +@Since: 2.4 + + + + + + +@node: +@copy_func: +@data: +@Returns: + + Inserts a #GNode beneath the parent at the given position. diff --git a/glib/gnode.c b/glib/gnode.c index c31a1804e..b5bce67fc 100644 --- a/glib/gnode.c +++ b/glib/gnode.c @@ -229,6 +229,45 @@ g_node_unlink (GNode *node) 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) { diff --git a/glib/gnode.h b/glib/gnode.h index 6d79ab0a4..7cc4fb000 100644 --- a/glib/gnode.h +++ b/glib/gnode.h @@ -55,6 +55,8 @@ typedef gboolean (*GNodeTraverseFunc) (GNode *node, gpointer data); typedef void (*GNodeForeachFunc) (GNode *node, gpointer data); +typedef gpointer (*GCopyFunc) (gconstpointer src, + gpointer data); /* N-way tree implementation */ @@ -77,6 +79,9 @@ void g_node_pop_allocator (void); 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,