changeset 1372:0afd598a0b30

Add clone_from_subtree() for coord object of nodejs
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 07 Mar 2011 09:38:09 +0800
parents 36cbe73813a8
children f02b39079ab0
files include/mb_redraw_man.h nodejs/coord.cc nodejs/coord.m4 src/redraw_man.c
diffstat 4 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_redraw_man.h	Sun Mar 06 19:31:28 2011 +0800
+++ b/include/mb_redraw_man.h	Mon Mar 07 09:38:09 2011 +0800
@@ -128,8 +128,9 @@
 
 extern coord_t *rdman_coord_new(redraw_man_t *rdman, coord_t *parent);
 extern int rdman_coord_free(redraw_man_t *rdman, coord_t *coord);
-extern coord_t * rdman_coord_clone_subtree(redraw_man_t *rdman,
-					   coord_t *parent, coord_t *src);
+extern coord_t * rdman_coord_clone_from_subtree(redraw_man_t *rdman,
+						coord_t *parent,
+						coord_t *src);
 extern int rdman_coord_subtree_free(redraw_man_t *rdman, coord_t *subtree);
 extern int rdman_coord_changed(redraw_man_t *rdman, coord_t *coord);
 extern int rdman_shape_changed(redraw_man_t *rdman, shape_t *shape);
--- a/nodejs/coord.cc	Sun Mar 06 19:31:28 2011 +0800
+++ b/nodejs/coord.cc	Mon Mar 07 09:38:09 2011 +0800
@@ -232,6 +232,26 @@
     xnjsmb_coord_free_subtree(rdman, coord);
 }
 
+static coord_t *
+xnjsmb_coord_clone_from_subtree(coord_t *coord, Handle<Object> self,
+				coord_t *src, const char **err) {
+    Handle<Object> js_rt;
+    redraw_man_t *rdman;
+    coord_t *cloning;
+
+    js_rt = GET(self, "mbrt")->ToObject();
+    ASSERT(js_rt != NULL);
+    rdman = xnjsmb_rt_rdman(js_rt);
+
+    cloning = rdman_coord_clone_from_subtree(rdman, coord, src);
+    if(cloning == NULL) {
+	*err = "can not clone a subtree (allocate memory)";
+	return NULL;
+    }
+
+    return cloning;
+}
+
 static void
 xnjsmb_coord_show(coord_t *coord, Handle<Object> self) {
     Handle<Object> js_rt;
--- a/nodejs/coord.m4	Sun Mar 06 19:31:28 2011 +0800
+++ b/nodejs/coord.m4	Mon Mar 07 09:38:09 2011 +0800
@@ -8,6 +8,9 @@
 	[METHOD([add_shape], [xnjsmb_coord_add_shape],
 		(SELF, OBJ([shape], [shape], [shape_t]), ERR), 1, []),
 	 METHOD([remove], [xnjsmb_coord_remove], (SELF), 0, []),
+	 METHOD([clone_from_subtree], [xnjsmb_coord_clone_from_subtree],
+	 	(SELF, OBJ([src], [coord], [coord_t]), ERR), 1,
+		[OBJ([coord], [coord_t])]),
 	 METHOD([show], [xnjsmb_coord_show], (SELF), 0, []),
 	 METHOD([hide], [xnjsmb_coord_hide], (SELF), 0, [])],
 	((GET_INDEX, (coord_get_index, NUMBER)),
--- a/src/redraw_man.c	Sun Mar 06 19:31:28 2011 +0800
+++ b/src/redraw_man.c	Mon Mar 07 09:38:09 2011 +0800
@@ -1109,8 +1109,8 @@
  * \return the root of new subtree.
  */
 coord_t *
-rdman_coord_clone_subtree(redraw_man_t *rdman,
-			  coord_t *parent, coord_t *src) {
+rdman_coord_clone_from_subtree(redraw_man_t *rdman,
+			       coord_t *parent, coord_t *src) {
     coord_t *cloning;
     coord_t *child;
     shape_t *member, *cloning_member;
@@ -1137,7 +1137,7 @@
 	    member_idx++;
 	}
 
-	rdman_coord_clone_subtree(rdman, cloning, child);
+	rdman_coord_clone_from_subtree(rdman, cloning, child);
     }
     
     /* Clone remain members after last child if any */
@@ -3108,7 +3108,7 @@
 }
 
 static void
-test_rdman_coord_clone_subtree(void) {
+test_rdman_coord_clone_from_subtree(void) {
     redraw_man_t _rdman;
     redraw_man_t *rdman;
     coord_t *coord1, *coord2, *coord3;
@@ -3136,7 +3136,7 @@
     coord3 = rdman_coord_new(rdman, coord2);
     CU_ASSERT(coord3 != NULL);
 
-    cloning = rdman_coord_clone_subtree(rdman, rdman->root_coord, coord1);
+    cloning = rdman_coord_clone_from_subtree(rdman, rdman->root_coord, coord1);
     CU_ASSERT(NEXT_CHILD(coord1) == cloning);
     
     cloning_visit = FIRST_CHILD(cloning);
@@ -3159,7 +3159,7 @@
     CU_ADD_TEST(suite, test_own_canvas_area);
     CU_ADD_TEST(suite, test_own_canvas);
     CU_ADD_TEST(suite, test_own_canvas_redraw);
-    CU_ADD_TEST(suite, test_rdman_coord_clone_subtree);
+    CU_ADD_TEST(suite, test_rdman_coord_clone_from_subtree);
 
     return suite;
 }