comparison m-toolbox/classes/@plist/removeKeys.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 % REMOVEKEYS removes keys from a PLIST.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Removes from the first input PLIST the keys which are
5 % specified as the second in a cell-array.
6 % This method will keep the oder of the keys inside the PLIST.
7 %
8 % CALL: pl = removeKeys(pl, 'key');
9 % pl = removeKeys(pl, {keys});
10 % pl = removeKeys(pl, plist('remove', {keys}));
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'removeKeys')">Parameters Description</a>
13 %
14 % VERSION: $Id: removeKeys.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 function varargout = removeKeys(varargin)
19
20 %%% Check if this is a call for parameters
21 if utils.helper.isinfocall(varargin{:})
22 varargout{1} = getInfo(varargin{3});
23 return
24 end
25
26 %%% Check input objects
27 if nargin ~= 2
28 error('### Unknown number of inputs. ');
29 end
30 if ~isa(varargin{1}, 'plist') || numel(varargin{1}) ~= 1
31 error('### The first input must be a single parameter list (PLIST).');
32 end
33 if ~(iscell(varargin{2}) || ischar(varargin{2}) || isa(varargin{2}, 'plist'))
34 error('### The second input must be a cell array, a string or a PLIST which controles this method.')
35 end
36
37 obj = varargin{1};
38 removeKeys = varargin{2};
39
40 %%% Convert the second input to a cell array if necessary.
41 if isa(removeKeys, 'plist')
42 removeKeys = removeKeys.find('remove');
43 end
44 if ischar(removeKeys)
45 removeKeys = cellstr(removeKeys);
46 end
47 removeKeys = upper(removeKeys);
48
49 %%% Decide on a deep copy or a modify
50 obj = copy(obj, nargout);
51
52 keys = {obj.params(:).key};
53
54 removeIndex = ~utils.helper.ismember(keys, removeKeys);
55 obj.params = obj.params(removeIndex);
56
57 varargout{1} = obj;
58 end
59
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 % Local Functions %
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %
66 % FUNCTION: getInfo
67 %
68 % DESCRIPTION: Get Info Object
69 %
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71
72 function ii = getInfo(varargin)
73 if nargin == 1 && strcmpi(varargin{1}, 'None')
74 sets = {};
75 pl = [];
76 else
77 sets = {'Default'};
78 pl = getDefaultPlist;
79 end
80 % Build info object
81 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: removeKeys.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $', sets, pl);
82 ii.setArgsmin(2);
83 ii.setArgsmax(2);
84 end
85
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %
88 % FUNCTION: getDefaultPlist
89 %
90 % DESCRIPTION: Get Default Plist
91 %
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 function pl = getDefaultPlist()
95
96 pl = plist();
97
98 % Remove
99 p = param({'remove', 'A list of the parameters to remove, specified by their keys.'}, {1, {'{}'}, paramValue.OPTIONAL});
100 pl.append(p);
101
102 end
103