comparison m-toolbox/classes/@plist/getIndexForKey.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 % GETINDEXFORKEY returns the index of a parameter with the given key.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: GETINDEXFORKEY returns the index of a parameter with the
5 % given key or -1 if the key is not found.
6 %
7 % CALL: idx = getIndexForKey(pl, 'key')
8 % idx = getIndexForKey(pl, pl)
9 %
10 % EXAMPLES:
11 %
12 % 1) idx = pl.getIndexForKey('foo') % get the parameter with key 'foo'
13 % 2) idx = pl.getIndexForKey(plist('key', 'WIN')) % get the parameter with key 'WIN'
14 %
15 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'getIndexForKey')">Parameters Description</a>
16 %
17 % VERSION: $Id: getIndexForKey.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $
18 %
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20
21 function varargout = getIndexForKey(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 if nargin ~= 2
30 error('### Incorrect inputs')
31 end
32
33 pl = varargin{1};
34 if isa(varargin{2}, 'plist')
35 key = varargin{2}.find('key');
36 else
37 key = varargin{2};
38 end
39
40 %%%%%%%%%% Some plausibility checks %%%%%%%%%%
41 if numel(pl) ~= 1
42 error('### This function could only work with one plist-object');
43 end
44
45 if ~ischar(key)
46 error('### The ''key'' must be a string but it is from the class %s.', class(key));
47 end
48
49 if ~isempty(pl.params)
50 dkeys = {pl.params(:).key};
51 else
52 dkeys = {''};
53 end
54
55 % Get index of the key we want
56 matches = strcmpi(key, dkeys);
57 varargout{1} = find(matches);
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: getIndexForKey.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $', sets, pl);
82 ii.setModifier(false);
83 ii.setArgsmin(1);
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 % Key
99 p = param({'key', 'The key of the parameter to get the index of.'}, paramValue.EMPTY_STRING);
100 pl.append(p);
101
102 end
103