dbf0c4516a84a264feedc5fc5cc34e50f2a07f54
[scilab.git] / scilab / modules / overloading / macros / generic_i_h.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
9
10 function h=generic_i_h(i,v,h)
11     hsave=h
12     //  if v==[] then error('Field property cannot be []'),end
13     if type(i)==10 then set(h,i,v),return,end
14     if type(i)<>15 then  error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1)),end
15
16     if and(type(i($))<>[1 2 4 8 129 15]) then
17         i($+1)=:
18     end
19     n=lstsize(i)
20     hdl=h;hind=[]
21     for k=1:lstsize(i)// walk down in the handle tree
22         p=i(k)
23         lasthandle=hdl,
24         if type(p)==10 then
25             hdl=get(hdl,p),
26         elseif or(type(p)==[1 2 4 8 129]) then
27             hdl=hdl(p)
28         elseif type(p)==15 then
29             hdl=hdl(p(:))
30         else
31             error("Invalid path")
32         end
33         if type(hdl)<>9 then //a leaf found
34             property=hdl
35             hdl=lasthandle
36             hind=p
37             if (k+1)==size(i) then
38                 index=i($)
39             else
40                 index=list(i(k+1:$))
41             end
42             break
43         end
44     end
45
46     if hind<>[] then // a property found
47         if type(index)==15 & and(type(property)<>[15 16 17]) then
48             property(index(:))=v
49         else
50             if or(size(index)<>[-1 -1]) then
51                 if (index(1)=="locations" | index(1)=="labels") & size(property(index),"*") ~= size(v,"*") then
52                     error(msprintf(_("%s: Incompatible sizes for properties ''%s'' and ''%s'': Same sizes expected.\n"), "generic_i_h", string(i($-2))+".locations", string(i($-2))+".labels"));
53                 end
54                 property(index)=v
55             else
56                 property=v
57             end
58         end
59         if size(hdl,"*")==1 then //a single handle
60             hdl(hind)=property
61         else //mutiple handle
62             np=size(hdl,"*")
63             for k=1:np
64                 h=hdl(k);h(hind)=property
65             end
66
67         end
68     else
69         error(msprintf(_("%s: Wrong type for input argument #%d.\n"),"generic_i_h",1));
70     end
71     h = hsave
72 endfunction