Ignore:
Timestamp:
Feb 17, 2016, 12:52:48 PM (9 years ago)
Author:
sommeria
Message:

xmltree updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/@xmltree/copy.m

    r723 r925  
    66% subuid    - UID of the subtree to copy
    77% uid       - UID of the element where the subtree must be duplicated
    8 %_______________________________________________________________________
     8%__________________________________________________________________________
    99%
    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
     10% Copy a subtree to another branch.
     11% The tree parameter must be in input AND in output.
     12%__________________________________________________________________________
     13% Copyright (C) 2002-2015  http://www.artefact.tk/
    1414
    15 error(nargchk(2,3,nargin));
     15% Guillaume Flandin
     16% $Id: copy.m 6480 2015-06-13 01:08:30Z guillaume $
     17
     18
     19%error(nargchk(2,3,nargin));
     20
    1621if nargin == 2
    17         uid = parent(tree,subuid);
     22    uid = parent(tree,subuid);
    1823end
    1924
     
    2227tree.tree{uid}.contents = [tree.tree{uid}.contents l+1];
    2328
    24 % pour que la copie soit a cote de l'original et pas a la fin ?
     29% to have the copy next to the original and not at the end?
    2530%  contents = get(tree,parent,'contents');
    2631%  i = find(contents==uid);
    2732%  tree = set(tree,parent,'contents',[contents(1:i) l+1 contents(i+1:end)]);
    2833
    29 %=======================================================================
     34%==========================================================================
    3035function tree = sub_copy(tree,uid,p)
    3136
    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
     37    l = length(tree);
     38    tree.tree{l+1} = tree.tree{uid};
     39    tree.tree{l+1}.uid = l+1;
     40    tree.tree{l+1}.parent = p;
     41    tree.tree{l+1}.contents = [];
     42    if isfield(tree.tree{uid},'contents')
     43        contents = get(tree,uid,'contents');
     44        m = length(tree);
     45        for i=1:length(contents)
     46            tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1];
     47            tree = sub_copy(tree,contents(i),l+1);
     48            m = length(tree);
     49        end
     50    end
Note: See TracChangeset for help on using the changeset viewer.