comparison m-toolbox/classes/@ao/search.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SEARCH selects AOs that match the given name.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SEARCH selects AOs that match the given name using a regular
5 % expression (help regexp).
6 %
7 % CALL: b = search(a, 'foo') % get all AOs from <a> called 'foo'
8 % b = search(a, 'foo*') % get all AOs from <a> with a name like 'foo'
9 % b = search(a, pl)
10 %
11 %
12 % This function returns the handles of the AOs that match the regular
13 % expression. No object copying is done.
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'search')">Parameters Description</a>
16 %
17 % VERSION: $Id: search.m,v 1.15 2011/04/08 08:56:11 hewitson Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 function varargout = search(varargin)
22
23 % Check if this is a call for parameters
24 if utils.helper.isinfocall(varargin{:})
25 varargout{1} = getInfo(varargin{3});
26 return
27 end
28
29 import utils.const.*
30 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
31
32 % Check output
33 if nargout == 0
34 error('### The search method can not be used as a modifier.');
35 end
36
37 % Collect input variable names
38 in_names = cell(size(varargin));
39 for ii = 1:nargin,in_names{ii} = inputname(ii);end
40
41 % Collect all AOs and plists
42 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
43 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
44
45 % Combine PLISTs
46 pl = combine(pl, getDefaultPlist);
47
48 % Decide on a deep copy or a modify
49 as = copy(as, nargout);
50
51 % Build a cell array of the input AO names
52 aonames = {};
53 for j=1:numel(as)
54 aonames = [aonames {as(j).name}];
55 end
56
57 %----- Get expression
58 % first look in direct inputs
59 exp = '';
60 for j=1:numel(rest)
61 if ischar(rest{j})
62 exp = rest{j};
63 break;
64 end
65 end
66 % then in plist
67 if isempty(exp)
68 exp = find(pl, 'regexp');
69 end
70 if isempty(exp)
71 error('### Please specify an expression to match.');
72 end
73
74 % Run regexp
75 exact = pl.find('exact');
76 if exact
77 res = strcmp(aonames, exp);
78 else
79 res = regexp(aonames, exp);
80 end
81
82 % Make sure that the search expression is in the history PLIST
83 pl.pset('regexp', exp);
84
85 % Get indices
86 bs = [];
87 for j=1:numel(res)
88 if exact
89 if res(j)
90 as(j).addHistory(getInfo('None'), pl, ao_invars(j), as(j).hist);
91 bs = [bs as(j)];
92 end
93 else
94 if ~isempty(res{j})
95 % Append history
96 as(j).addHistory(getInfo('None'), pl, ao_invars(j), as(j).hist);
97 bs = [bs as(j)];
98 end
99 end
100 end
101
102 % Set output
103 if nargout == numel(bs)
104 % List of outputs
105 for ii = 1:numel(bs)
106 varargout{ii} = bs(ii);
107 end
108 else
109 % Single output
110 varargout{1} = bs;
111 end
112 end
113
114 %--------------------------------------------------------------------------
115 % Get Info Object
116 %--------------------------------------------------------------------------
117 function ii = getInfo(varargin)
118 if nargin == 1 && strcmpi(varargin{1}, 'None')
119 sets = {};
120 pl = [];
121 else
122 sets = {'Default'};
123 pl = getDefaultPlist;
124 end
125 % Build info object
126 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: search.m,v 1.15 2011/04/08 08:56:11 hewitson Exp $', sets, pl);
127 end
128
129 %--------------------------------------------------------------------------
130 % Get Default Plist
131 %--------------------------------------------------------------------------
132 function plout = getDefaultPlist()
133 persistent pl;
134 if exist('pl', 'var')==0 || isempty(pl)
135 pl = buildplist();
136 end
137 plout = pl;
138 end
139
140 function pl = buildplist()
141 pl = plist();
142
143 % regexp
144 p = param({'regexp', 'A string specifying the regular expression'}, paramValue.EMPTY_STRING);
145 pl.append(p);
146
147 % exact
148 p = param({'exact', 'A boolean specifying to look for an exact match or not'}, paramValue.FALSE_TRUE);
149 pl.append(p);
150
151 end
152
153 % PARAMETERS: 'regexp' - a string specifying the regular expression