Mercurial > hg > ltpda
comparison m-toolbox/classes/@plist/setDescriptionForParam.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 % SETDESCRIPTIONFORPARAM Sets the property 'desc' of the param object in dependencies of the 'key' | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Sets the property 'desc' of the param object in dependencies | |
5 % of the 'key' | |
6 % | |
7 % CALL: obj = obj.setDescriptionForParam('key', 'description for the key'); | |
8 % obj = obj.setDescriptionForParam(plist('key', 'key', 'desc', 'description for the key')); | |
9 % obj = setDescriptionForParam(obj, 'key', 'description for the key'); | |
10 % | |
11 % INPUTS: obj - can be a vector, matrix, list, or a mix of them. | |
12 % pl - to set the description of a key with a plist, please | |
13 % specify only one plist with the key-words 'key' and | |
14 % 'desc' | |
15 % | |
16 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'setDescriptionForParam')">Parameters Description</a> | |
17 % | |
18 % VERSION: $Id: setDescriptionForParam.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $ | |
19 % | |
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
21 | |
22 function varargout = setDescriptionForParam(varargin) | |
23 | |
24 %%% Check if this is a call for parameters | |
25 if utils.helper.isinfocall(varargin{:}) | |
26 varargout{1} = getInfo(varargin{3}); | |
27 return | |
28 end | |
29 | |
30 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist'); | |
31 | |
32 for kk = 1:numel(objs) | |
33 pls = objs(kk); | |
34 %%% If the plist contains only two key/value pairs with the keys 'key' | |
35 %%% and 'desc' then set the description with this plist. | |
36 if pls.nparams == 2 && pls.isparam('key') && pls.isparam('desc') | |
37 rest{1} = pls.find('key'); | |
38 rest{2} = pls.find('desc'); | |
39 objs(kk) = []; | |
40 break; | |
41 end | |
42 end | |
43 | |
44 if numel(rest) ~= 2 | |
45 error('### Please specify a description AND a key for this description, either in a plist or directly.'); | |
46 end | |
47 | |
48 key = rest{1}; | |
49 desc = rest{2}; | |
50 | |
51 %%% Check that the description is a string | |
52 if ~ischar(desc) | |
53 error('### The description for the key ''%s'' must be a string but it is from the class [%s]', key, class(desc)); | |
54 end | |
55 | |
56 %%% Set the Name | |
57 for ii = 1:numel(objs) | |
58 | |
59 %%% decide whether we modify the first plist, or create a new one. | |
60 objs(ii) = copy(objs(ii), nargout); | |
61 | |
62 for kk = 1:objs(ii).nparams | |
63 if strcmpi(key, objs(ii).params(kk).key) | |
64 objs(ii).params(kk).setDesc(desc); | |
65 end | |
66 end | |
67 end | |
68 | |
69 %%% Set output | |
70 if nargout == numel(objs) | |
71 % List of outputs | |
72 for ii = 1:numel(objs) | |
73 varargout{ii} = objs(ii); | |
74 end | |
75 else | |
76 % Single output | |
77 varargout{1} = objs; | |
78 end | |
79 end | |
80 | |
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: setDescriptionForParam.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $', sets, pl); | |
104 end | |
105 | |
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
107 % | |
108 % FUNCTION: getDefaultPlist | |
109 % | |
110 % DESCRIPTION: Get Default Plist | |
111 % | |
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
113 | |
114 function pl = getDefaultPlist() | |
115 | |
116 pl = plist(); | |
117 | |
118 % Key | |
119 p = param({'key', 'The key of the parameter to set the description for.'}, paramValue.EMPTY_STRING); | |
120 pl.append(p); | |
121 | |
122 % Index | |
123 p = param({'desc', 'The description to set.'}, paramValue.EMPTY_STRING); | |
124 pl.append(p); | |
125 | |
126 end | |
127 | |
128 |