comparison m-toolbox/classes/@plist/subset.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 % SUBSET returns a subset of a parameter list.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SUBSET returns a subset of a parameter list.
5 %
6 % CALL: p = subset(pl, 'key')
7 % p = subset(pl, search_pl)
8 % p = subset(pl, 'key1', 'key2')
9 % p = subset(pl, {'key1', 'key2'})
10 %
11 % A warning is given for any key not in the original plist.
12 %
13 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'subset')">Parameters Description</a>
14 %
15 % VERSION: $Id: subset.m,v 1.6 2011/04/08 08:56:20 hewitson Exp $
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 function varargout = subset(varargin)
20
21 %%% Check if this is a call for parameters
22 if utils.helper.isinfocall(varargin{:})
23 varargout{1} = getInfo(varargin{3});
24 return
25 end
26
27 % Check inputs
28 if nargin < 2
29 error('### Incorrect inputs')
30 end
31
32 if nargout ~= 1
33 error('### Incorrect outputs. plist/subset cannot be used as a modifier.');
34 end
35
36 % The first input is the plist to extract the subset of
37 pl = varargin{1};
38
39 % Collect the keys to search for
40 keys = {};
41 for kk=2:nargin
42 if iscell(varargin{kk})
43 keys = [keys varargin{kk}];
44 elseif isa(varargin{kk}, 'plist')
45 pli = varargin{kk};
46 ikeys = pli.find('keys');
47 if ~isempty(ikeys)
48 keys = [keys ikeys];
49 end
50 else
51 keys = [keys varargin(kk)];
52 end
53 end
54
55 % Convert input keys to upper case
56 keys = upper(keys);
57
58 % Check we got some keys
59 if isempty(keys)
60 error('### Please specify at least one key');
61 end
62
63 % We only handle one input plist
64 if numel(pl) ~= 1
65 error('### This function can only work with one plist-object');
66 end
67
68 % Get parameters we want
69 pl_out = plist();
70 for kk=1:pl.nparams
71 if ismember(pl.params(kk).key, keys)
72 pl_out.append(copy(pl.params(kk),1));
73 end
74 end
75
76 % Check the plist contains all the requested keys
77 for kk=1:numel(keys)
78 if pl_out.nparams == 0 || ~ismember(keys{kk}, {pl_out.params(:).key})
79 warning('The key ''%s'' was not found in the original plist', keys{kk});
80 end
81 end
82
83 % Set output
84 if nargout == 1
85 varargout{1} = pl_out;
86 else
87 error('### Incorrect number of outputs');
88 end
89 end
90
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 % Local Functions %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %
97 % FUNCTION: getInfo
98 %
99 % DESCRIPTION: Get Info Object
100 %
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102
103 function ii = getInfo(varargin)
104 if nargin == 1 && strcmpi(varargin{1}, 'None')
105 sets = {};
106 pl = [];
107 else
108 sets = {'Default'};
109 pl = getDefaultPlist;
110 end
111 % Build info object
112 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: subset.m,v 1.6 2011/04/08 08:56:20 hewitson Exp $', sets, pl);
113 ii.setModifier(false);
114 ii.setArgsmin(1);
115 end
116
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118 %
119 % FUNCTION: getDefaultPlist
120 %
121 % DESCRIPTION: Get Default Plist
122 %
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
125 function pl = getDefaultPlist()
126
127 pl = plist();
128
129 % Keys
130 p = param({'keys', 'The keys to search for.'}, paramValue.EMPTY_STRING);
131 pl.append(p);
132
133 end
134