SEARCH selects AOs that match the given name. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SEARCH selects AOs that match the given name using a regular expression (help regexp). CALL: b = search(a, 'foo') % get all AOs from <a> called 'foo' b = search(a, 'foo*') % get all AOs from <a> with a name like 'foo' b = search(a, pl) PARAMETERS: 'regexp' - a string specifying the regular expression This function returns the handles of the AOs that match the regular expression. No object copying is done. M-FILE INFO: Get information about this methods by calling >> ao.getInfo('search') Get information about a specified set-plist by calling: >> ao.getInfo('search', 'None') VERSION: $Id: search.m,v 1.4 2008/09/05 11:05:29 ingo Exp $ HISTORY: 10-07-08 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % SEARCH selects AOs that match the given name. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: SEARCH selects AOs that match the given name using a regular 0005 % expression (help regexp). 0006 % 0007 % CALL: b = search(a, 'foo') % get all AOs from <a> called 'foo' 0008 % b = search(a, 'foo*') % get all AOs from <a> with a name like 'foo' 0009 % b = search(a, pl) 0010 % 0011 % PARAMETERS: 'regexp' - a string specifying the regular expression 0012 % 0013 % This function returns the handles of the AOs that match the regular 0014 % expression. No object copying is done. 0015 % 0016 % M-FILE INFO: Get information about this methods by calling 0017 % >> ao.getInfo('search') 0018 % 0019 % Get information about a specified set-plist by calling: 0020 % >> ao.getInfo('search', 'None') 0021 % 0022 % VERSION: $Id: search.m,v 1.4 2008/09/05 11:05:29 ingo Exp $ 0023 % 0024 % HISTORY: 10-07-08 M Hewitson 0025 % Creation 0026 % 0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0028 0029 function varargout = search(varargin) 0030 0031 % Check if this is a call for parameters 0032 if utils.helper.isinfocall(varargin{:}) 0033 varargout{1} = getInfo(varargin{3}); 0034 return 0035 end 0036 0037 import utils.const.* 0038 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0039 0040 % Collect input variable names 0041 in_names = cell(size(varargin)); 0042 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0043 0044 % Collect all AOs and plists 0045 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0046 [pl, pl_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0047 0048 % Build a cell array of the input AO names 0049 aonames = {}; 0050 for j=1:numel(as) 0051 aonames = [aonames {as(j).name}]; 0052 end 0053 0054 %----- Get expression 0055 % first look in direct inputs 0056 exp = ''; 0057 for j=1:numel(rest) 0058 if ischar(rest{j}) 0059 exp = rest{j}; 0060 break; 0061 end 0062 end 0063 % then in plist 0064 if isempty(exp) 0065 exp = find(pl, 'regexp'); 0066 end 0067 if isempty(exp) 0068 error('### Please specify an expression to match.'); 0069 end 0070 0071 % Run regexp 0072 res = regexp(aonames, exp); 0073 0074 % Get indices 0075 bs = []; 0076 for j=1:numel(res) 0077 if ~isempty(res{j}) 0078 bs = [bs as(j)]; 0079 end 0080 end 0081 0082 % Set outputs 0083 varargout{1} = bs; 0084 end 0085 0086 %-------------------------------------------------------------------------- 0087 % Get Info Object 0088 %-------------------------------------------------------------------------- 0089 function ii = getInfo(varargin) 0090 if nargin == 1 && strcmpi(varargin{1}, 'None') 0091 sets = {}; 0092 pl = []; 0093 else 0094 sets = {'Default'}; 0095 pl = getDefaultPlist; 0096 end 0097 % Build info object 0098 ii = minfo(mfilename, 'ao', '', utils.const.categories.helper, '$Id: search.m,v 1.4 2008/09/05 11:05:29 ingo Exp $', sets, pl); 0099 end 0100 0101 %-------------------------------------------------------------------------- 0102 % Get Default Plist 0103 %-------------------------------------------------------------------------- 0104 function pl_default = getDefaultPlist() 0105 pl_default = plist('regexp', ''); 0106 end 0107