samer@0: function u=construct(s,sizes_in) samer@0: nin=nargin(s.base); samer@0: nout=nargout(s.base); samer@0: samer@0: running=0; samer@0: current_arrow = s.base; samer@0: current_unit = construct(current_arrow,sizes_in(1:nin)); samer@0: current_proc = current_unit.process; samer@0: samer@0: u=mkunit(s); samer@0: u.sizes_out = current_unit.sizes_out; samer@0: u.starting = @starting; samer@0: u.stopping = @stopping; samer@0: u.dispose = @dispose; samer@0: u.get_state = @get_state; samer@0: u.set_state = @set_state; samer@0: samer@0: if nin==1 && nout==1, u.process=@proc_11; samer@0: elseif nin==1 && nout==0, u.process=@proc_10; samer@0: elseif nin==0 && nout==1, u.process=@proc_01; samer@0: else, u.process=@proc_nn; end samer@0: samer@0: function starting, current_unit.starting(); running=1; end samer@0: function stopping, current_unit.stopping(); running=0; end samer@0: function dispose, current_unit.dispose(); end samer@0: samer@0: function s=get_state, s={current_arrow, current_unit.get_state()}; end samer@0: function set_state(s), replace_running_unit(s{1},s{2}); end samer@0: samer@0: function y1=proc_11(x1,x), samer@0: if ~isempty(x), replace_running_unit(x{1}); end samer@0: y1=current_proc(x1); samer@0: end samer@0: samer@0: function x=proc_10(x1,x), samer@0: if ~isempty(x), replace_running_unit(x{1}); end samer@0: current_proc(x1); samer@0: end samer@0: function y1=proc_01(x), samer@0: if ~isempty(x), replace_running_unit(x{1}); end samer@0: y1=current_proc(); samer@0: end samer@0: samer@0: function varargout=proc_nn(varargin) samer@0: x=varargin{end}; samer@0: if ~isempty(x), replace_running_unit(x{1}); end samer@0: [varargout{1:nout}]=current_proc(varargin{1:nin}); samer@0: end samer@0: samer@0: function replace_running_unit(a,state) samer@0: if running samer@0: current_unit.stopping(); samer@0: current_unit.dispose(); samer@0: end samer@0: current_arrow=a; samer@0: current_unit=construct(a,sizes_in(1:nin)); samer@0: current_proc=current_unit.process; samer@0: if nargin>1, current_unit.set_state(state); end samer@0: if running, current_unit.starting(); end samer@0: end samer@0: end samer@0: samer@0: