source: trunk/src/@xmltree/copy.m @ 765

Last change on this file since 765 was 723, checked in by sommeria, 11 years ago

xmltree and toolbox_calib added to svn

File size: 1.5 KB
Line 
1function tree = copy(tree,subuid,uid)
2% XMLTREE/COPY Copy Method (copy a subtree in another branch)
3% FORMAT tree = copy(tree,subuid,uid)
4%
5% tree      - XMLTree object
6% subuid    - UID of the subtree to copy
7% uid       - UID of the element where the subtree must be duplicated
8%_______________________________________________________________________
9%
10% Copy a subtree to another branch
11% The tree parameter must be in input AND in output
12%_______________________________________________________________________
13% @(#)copy.m                   Guillaume Flandin               02/04/08
14
15error(nargchk(2,3,nargin));
16if nargin == 2
17        uid = parent(tree,subuid);
18end
19
20l = length(tree);
21tree = sub_copy(tree,subuid,uid);
22tree.tree{uid}.contents = [tree.tree{uid}.contents l+1];
23
24% pour que la copie soit a cote de l'original et pas a la fin ?
25%  contents = get(tree,parent,'contents');
26%  i = find(contents==uid);
27%  tree = set(tree,parent,'contents',[contents(1:i) l+1 contents(i+1:end)]);
28
29%=======================================================================
30function tree = sub_copy(tree,uid,p)
31
32        l = length(tree);
33        tree.tree{l+1} = tree.tree{uid};
34        tree.tree{l+1}.uid = l+1;
35        tree.tree{l+1}.parent = p;
36        tree.tree{l+1}.contents = [];
37        if isfield(tree.tree{uid},'contents')
38                contents = get(tree,uid,'contents');
39                m = length(tree);
40                for i=1:length(contents)
41                        tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1];
42                        tree = sub_copy(tree,contents(i),l+1);
43                        m = length(tree);
44                end
45        end
Note: See TracBrowser for help on using the repository browser.