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