comparison m-toolbox/classes/@plist/find.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 % FIND overloads find routine for a parameter list.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: FIND overloads find routine for a parameter list.
5 % Returns the value corresponding to the first parameter in
6 % the list with the search-key.
7 % An optional argument can be passed so it is assigned to the
8 % return in case the search-key was not found.
9 %
10 % CALL: a = find(pl, 'key')
11 % a = find(pl, pl)
12 % a = find(pl, 'key', opt_val)
13 % a = find(pl, pl, opt_val)
14 %
15 %
16 % EXAMPLES:
17 %
18 % 1) a = pl.find('foo') % get the parameter with key 'foo'
19 % 2) a = pl.find(plist('key', 'WIN')) % get the parameter with key 'WIN'
20 % 3) a = pl.find('foo', 1) % get the parameter with key 'foo', and get 1
21 % if the key was not present in the input plist
22 %
23 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'find')">Parameters Description</a>
24 %
25 % VERSION: $Id: find.m,v 1.25 2011/04/08 08:56:21 hewitson Exp $
26 %
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28
29 function varargout = find(varargin)
30
31 %%% Check if this is a call for parameters
32 if utils.helper.isinfocall(varargin{:})
33 varargout{1} = getInfo(varargin{3});
34 return
35 end
36
37 if nargin > 3 && nargin < 2
38 error('### Incorrect inputs')
39 end
40
41 pl = varargin{1};
42 if isa(varargin{2}, 'plist')
43 key = varargin{2}.find('key');
44 else
45 key = varargin{2};
46 end
47 def_val = [];
48 if nargin == 3
49 def_val = varargin{3};
50 end
51
52 %%%%%%%%%% Some plausibility checks %%%%%%%%%%
53 if numel(pl) ~= 1
54 error('### This function could only work with one plist-object');
55 end
56
57 if ~ischar(key)
58 error('### The ''key'' must be a string but it is from the class %s.', class(key));
59 end
60
61 if ~isempty(pl.params)
62 dkeys = {pl.params(:).key};
63 else
64 dkeys = {''};
65 end
66
67 % Get value we want
68 matches = strcmpi(key, dkeys);
69 if any(matches)
70 val = pl.params(matches).getVal;
71 else
72 val = def_val;
73 end
74
75 if isa(val, 'ltpda_obj')
76 varargout{1} = copy(val, 1);
77 else
78 varargout{1} = val;
79 end
80 end
81
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 % Local Functions %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %
88 % FUNCTION: getInfo
89 %
90 % DESCRIPTION: Get Info Object
91 %
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93
94 function ii = getInfo(varargin)
95 if nargin == 1 && strcmpi(varargin{1}, 'None')
96 sets = {};
97 pl = [];
98 else
99 sets = {'Default'};
100 pl = getDefaultPlist;
101 end
102 % Build info object
103 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: find.m,v 1.25 2011/04/08 08:56:21 hewitson Exp $', sets, pl);
104 ii.setModifier(false);
105 ii.setArgsmin(1);
106 end
107
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %
110 % FUNCTION: getDefaultPlist
111 %
112 % DESCRIPTION: Get Default Plist
113 %
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116 function pl = getDefaultPlist()
117
118 pl = plist();
119
120 % Key
121 p = param({'key', 'A key to search for.'}, paramValue.EMPTY_STRING);
122 pl.append(p);
123
124 end
125