summaryrefslogtreecommitdiffstats
path: root/scilab/modules/data_structures/macros/struct.sci
diff options
context:
space:
mode:
authorFarid Belahcene <farid.belahcene@inria.fr>2006-10-06 09:10:59 +0000
committerFarid Belahcene <farid.belahcene@inria.fr>2006-10-06 09:10:59 +0000
commit0a6c0e07067fbfb0d813229fd3a93e233e54d6bb (patch)
tree6ea7c16f93e04a0ca4199f92195ff9f1345e7f0c /scilab/modules/data_structures/macros/struct.sci
parenta81a6181fc55b124e3f0000a0269b5162cc5a900 (diff)
downloadscilab-0a6c0e07067fbfb0d813229fd3a93e233e54d6bb.zip
scilab-0a6c0e07067fbfb0d813229fd3a93e233e54d6bb.tar.gz
move the overloading functions for the cell and the struct
Diffstat (limited to 'scilab/modules/data_structures/macros/struct.sci')
-rw-r--r--scilab/modules/data_structures/macros/struct.sci63
1 files changed, 63 insertions, 0 deletions
diff --git a/scilab/modules/data_structures/macros/struct.sci b/scilab/modules/data_structures/macros/struct.sci
new file mode 100644
index 0000000..ab50138
--- /dev/null
+++ b/scilab/modules/data_structures/macros/struct.sci
@@ -0,0 +1,63 @@
1function s=struct(varargin)
2// Copyright INRIA
3// Equivalent for Matlab struct function
4// Author: V. Couvert
5
6rhs=argn(2)
7
8fields=["st","dims"]
9
10if rhs==0 then
11 // No Matlab equivalent
12 s=mlist(fields,int32([0,0]))
13 return
14end
15
16if floor(rhs/2)*2<>rhs then
17 error("Wrong number of inputs");
18end
19
20nbfields=size(varargin)/2
21
22dims=[]
23for kf=1:2:size(varargin)
24 fields=[fields varargin(kf)]
25end
26
27dims=[1 1]
28// Search struct size
29for kf=2:2:size(varargin)
30 if typeof(varargin(kf))=="ce" then
31 if or(double(varargin(kf).dims)<>[1 1]) then
32 dims=varargin(kf).dims
33 break
34 end
35 end
36end
37s=mlist(fields,int32(dims))
38
39// Search if one value is a scalar cell
40fnb=3
41for kf=2:2:size(varargin)
42 if typeof(varargin(kf))<>"ce" then
43 value=list()
44 for kk=1:prod(double(dims))
45 value(kk)=varargin(kf)
46 end
47 elseif and(double(varargin(kf).dims)==[1 1]) then
48 value=list()
49 for kk=1:prod(double(dims))
50 value(kk)=varargin(kf).entries
51 end
52 else
53 value=varargin(kf).entries
54 end
55 if prod(double(dims))==1 then
56 setfield(fnb,value(1),s)
57 else
58 setfield(fnb,value,s)
59 end
60 fnb=fnb+1
61end
62
63endfunction