comparison m-toolbox/classes/@plist/setDefaultForParam.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 % SETDEFAULTFORPARAM Sets the default value of the param object in dependencies of the 'key'
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: Sets the default value (index to the possible options) of
5 % the param object in dependencies of the 'key'.
6 %
7 % CALL: obj = obj.setDefaultForParam('key', newOption);
8 % obj = obj.setDefaultForParam(plist('KEY', 'key', 'option', newOption));
9 % obj = setDefaultForParam(obj, 'key', newOption);
10 %
11 % INPUTS: obj - can be a vector, matrix, list, or a mix of them.
12 % key - The key which should be changed
13 % newOption - new option for the selection mode
14 % OPTIONAL: If the new option doesn't exist in
15 % the param-options then add this
16 % method the 'new' option.
17 % SINGLE: Sets the 'new' option only if it is
18 % found in the param-options.
19 % pl - to set the default value of a key with a plist,
20 % please specify only one plist with the key-words
21 % 'key' and 'option'
22 %
23 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'setDefaultForParam')">Parameters Description</a>
24 %
25 % VERSION: $Id: setDefaultForParam.m,v 1.9 2011/07/08 08:18:07 mauro Exp $
26 %
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28
29 function varargout = setDefaultForParam(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 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist');
38
39 for kk = 1:numel(objs)
40 pls = objs(kk);
41 %%% If the plist contains only two key/value pairs with the keys 'key'
42 %%% and 'option' then set the default option with this plist.
43 if pls.nparams == 2 && pls.isparam('key') && pls.isparam('option')
44 rest{1} = pls.find('key');
45 rest{2} = pls.find('option');
46 objs(kk) = [];
47 break;
48 end
49 end
50
51 if numel(rest) ~= 2
52 error('### Please specify a ''key'' AND a the new option, either in a plist or direct.');
53 end
54
55 key = rest{1};
56 option = rest{2};
57
58 %%% Set the Name
59 for ii = 1:numel(objs)
60
61 %%% decide whether we modify the first plist, or create a new one.
62 objs(ii) = copy(objs(ii), nargout);
63
64 for kk = 1:objs(ii).nparams
65 if strcmpi(key, objs(ii).params(kk).key)
66 objs(ii).params(kk).setDefaultOption(option);
67 end
68 end
69 end
70
71 %%% Set output
72 varargout = utils.helper.setoutputs(nargout, objs);
73
74 end
75
76
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 % Local Functions %
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 %
83 % FUNCTION: getInfo
84 %
85 % DESCRIPTION: Get Info Object
86 %
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89 function ii = getInfo(varargin)
90 if nargin == 1 && strcmpi(varargin{1}, 'None')
91 sets = {};
92 pl = [];
93 else
94 sets = {'Default'};
95 pl = getDefaultPlist;
96 end
97 % Build info object
98 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: setDefaultForParam.m,v 1.9 2011/07/08 08:18:07 mauro Exp $', sets, pl);
99 end
100
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %
103 % FUNCTION: getDefaultPlist
104 %
105 % DESCRIPTION: Get Default Plist
106 %
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
109 function pl = getDefaultPlist()
110
111 pl = plist();
112
113 % Key
114 p = param({'key', 'The key of the parameter to set the default index for.'}, paramValue.EMPTY_STRING);
115 pl.append(p);
116
117 % Index
118 p = param({'options', 'The index to set.'}, paramValue.DOUBLE_VALUE(-1));
119 pl.append(p);
120
121 end
122