samer@0
|
1 function u=construct(s,sizes_in)
|
samer@0
|
2 nin=nargin(s.base);
|
samer@0
|
3 nout=nargout(s.base);
|
samer@0
|
4
|
samer@0
|
5 running=0;
|
samer@0
|
6 current_arrow = s.base;
|
samer@0
|
7 current_unit = construct(current_arrow,sizes_in(1:nin));
|
samer@0
|
8 current_proc = current_unit.process;
|
samer@0
|
9
|
samer@0
|
10 u=mkunit(s);
|
samer@0
|
11 u.sizes_out = current_unit.sizes_out;
|
samer@0
|
12 u.starting = @starting;
|
samer@0
|
13 u.stopping = @stopping;
|
samer@0
|
14 u.dispose = @dispose;
|
samer@0
|
15 u.get_state = @get_state;
|
samer@0
|
16 u.set_state = @set_state;
|
samer@0
|
17
|
samer@0
|
18 if nin==1 && nout==1, u.process=@proc_11;
|
samer@0
|
19 elseif nin==1 && nout==0, u.process=@proc_10;
|
samer@0
|
20 elseif nin==0 && nout==1, u.process=@proc_01;
|
samer@0
|
21 else, u.process=@proc_nn; end
|
samer@0
|
22
|
samer@0
|
23 function starting, current_unit.starting(); running=1; end
|
samer@0
|
24 function stopping, current_unit.stopping(); running=0; end
|
samer@0
|
25 function dispose, current_unit.dispose(); end
|
samer@0
|
26
|
samer@0
|
27 function s=get_state, s={current_arrow, current_unit.get_state()}; end
|
samer@0
|
28 function set_state(s), replace_running_unit(s{1},s{2}); end
|
samer@0
|
29
|
samer@0
|
30 function y1=proc_11(x1,x),
|
samer@0
|
31 if ~isempty(x), replace_running_unit(x{1}); end
|
samer@0
|
32 y1=current_proc(x1);
|
samer@0
|
33 end
|
samer@0
|
34
|
samer@0
|
35 function x=proc_10(x1,x),
|
samer@0
|
36 if ~isempty(x), replace_running_unit(x{1}); end
|
samer@0
|
37 current_proc(x1);
|
samer@0
|
38 end
|
samer@0
|
39 function y1=proc_01(x),
|
samer@0
|
40 if ~isempty(x), replace_running_unit(x{1}); end
|
samer@0
|
41 y1=current_proc();
|
samer@0
|
42 end
|
samer@0
|
43
|
samer@0
|
44 function varargout=proc_nn(varargin)
|
samer@0
|
45 x=varargin{end};
|
samer@0
|
46 if ~isempty(x), replace_running_unit(x{1}); end
|
samer@0
|
47 [varargout{1:nout}]=current_proc(varargin{1:nin});
|
samer@0
|
48 end
|
samer@0
|
49
|
samer@0
|
50 function replace_running_unit(a,state)
|
samer@0
|
51 if running
|
samer@0
|
52 current_unit.stopping();
|
samer@0
|
53 current_unit.dispose();
|
samer@0
|
54 end
|
samer@0
|
55 current_arrow=a;
|
samer@0
|
56 current_unit=construct(a,sizes_in(1:nin));
|
samer@0
|
57 current_proc=current_unit.process;
|
samer@0
|
58 if nargin>1, current_unit.set_state(state); end
|
samer@0
|
59 if running, current_unit.starting(); end
|
samer@0
|
60 end
|
samer@0
|
61 end
|
samer@0
|
62
|
samer@0
|
63
|