source: MML/trunk/applications/m2html/@template/get.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.4 KB
Line 
1function varargout = get(tpl,action,varargin)
2%TEMPLATE/GET Access data stored in a Template object
3%  TPL = GET(TPL,ACTION,VARARGIN)
4%     ACTION 'var'
5%     ACTION 'undefined'
6
7%  Copyright (C) 2003 Guillaume Flandin <Guillaume@artefact.tk>
8%  $Revision: 1.0 $Date: 2003/05/05 22:19:51 $
9
10error(nargchk(2,3,nargin));
11
12switch lower(action)
13        case 'var'
14                error(nargchk(2,3,nargin));
15                if nargin == 2
16                        varargout{1} = tpl.varvals;
17                elseif iscellstr(varargin{1})
18                        varargout{1} = {};
19                        for i=1:length(varargin{1})
20                                key = find(ismember(tpl.varkeys,varargin{1}{i}));
21                                if isempty(key)
22                                        %error('[Template] No such variable name.');
23                                        varargout{1}{end+1} = '';
24                                else
25                                        varargout{1}{end+1} = tpl.varvals{key};
26                                end
27                        end
28                elseif ischar(varargin{1})
29                        varargout{1} = char(get(tpl,'var',cellstr(varargin{1})));
30                else
31                        varargout{1} = '';
32                end
33        case 'undefined'
34                error(nargchk(3,3,nargin));
35                tpl = loadtpl(tpl,varargin{1});
36                str = get(tpl,'var',varargin{1});
37                varargout{1} = {};
38               
39                %%%%%%%%%%%%%%%%%%%%%%%% WIH REGEXP ONLY %%%%%%%%%%%%%%%%%%%%
40                % [b, e] = regexp(str,'{[^ \t\r\n}]+}');
41                % for i=1:length(b)
42                %       if ~any(ismember(tpl.varkeys,str(b(i)+1:e(i)-1)))
43                %               varargout{1}{end+1} = str(b(i)+1:e(i)-1);
44                %       end
45                % end
46                %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48        otherwise
49                varargout{1} = finish(get(tpl,'var',action),tpl.unknowns);
50end
Note: See TracBrowser for help on using the repository browser.