Mercurial > hg > ltpda
comparison m-toolbox/classes/@param/param.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 % PARAM Parameter object class constructor. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: PARAM Parameter object class constructor. | |
5 % Create a parameter object. | |
6 % | |
7 % SUPERCLASSES: ltpda_nuo < ltpda_obj | |
8 % | |
9 % CONSTRUCTORS: | |
10 % | |
11 % p = param(); - creates an empty parameter | |
12 % p = param(pl) - creates a parameter from a | |
13 % parameter list with the parameters: | |
14 % - 'key' and 'val', or | |
15 % p = param('key', val) - creates a key/value pair | |
16 % 'val' can be from any type | |
17 % p = param({key, desc}, val) - creates a key/value pair and a | |
18 % description for the key | |
19 % p = param('key', val, desc) - creates a key/value pair and a | |
20 % description for the key | |
21 % | |
22 % VERSION: $Id: param.m,v 1.72 2011/03/28 17:02:28 ingo Exp $ | |
23 % | |
24 % SEE ALSO: ltpda_obj, ltpda_nuo, plist | |
25 % | |
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
27 | |
28 classdef (Sealed = true, Hidden = true) param < ltpda_nuo | |
29 | |
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
31 % Property definition % | |
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
33 | |
34 %---------- Public (read/write) Properties ---------- | |
35 properties | |
36 end | |
37 | |
38 %---------- Protected read-only Properties ---------- | |
39 properties (SetAccess = protected) | |
40 key = ''; % key of the key/value pair | |
41 val = []; % value of the key/value pair | |
42 desc = ''; % description of the key/value pair | |
43 end | |
44 | |
45 %---------- Protected Properties ---------- | |
46 properties (SetAccess = protected) | |
47 end | |
48 | |
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
50 % Check property setting % | |
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
52 | |
53 methods | |
54 function set.key(obj, val) | |
55 if ischar(val) | |
56 obj.key = upper(val); | |
57 else | |
58 error('### The value for the property ''key'' must be a string\n### but it is from the class %s', class(val)); | |
59 end | |
60 end | |
61 end | |
62 | |
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
64 % Constructor % | |
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
66 | |
67 methods | |
68 function obj = param(varargin) | |
69 | |
70 switch nargin | |
71 case 0 | |
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
73 %%%%%%%%%%%%%%%%%%%%%%%%%%% no input %%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
75 | |
76 % Do nothing | |
77 | |
78 case 1 | |
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
80 %%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%% | |
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
82 | |
83 if isa(varargin{1}, 'param') | |
84 %%%%%%%%%% obj = param(param) %%%%%%%%%% | |
85 obj = copy(varargin{1}, 1); | |
86 | |
87 elseif isa(varargin{1}, 'plist') | |
88 %%%%%%%%%% obj = param(plist) %%%%%%%%%% | |
89 | |
90 if nparams(varargin{1}) == 0 | |
91 %%%%%%%%%% obj = param(plist()) %%%%%%%%%% | |
92 %%%%%%%%%% obj = param(plist('KEY', 'a', 'VAL', 1)) %%%%%%%%%% | |
93 %%% is the plist is empty then return an empty param object | |
94 | |
95 else | |
96 pl = varargin{1}; | |
97 pl_key = find(pl, 'key'); | |
98 pl_val = find(pl, 'val'); | |
99 pl_desc = find(pl, 'desc'); | |
100 if isempty(pl_key) | |
101 error('### building a parameter from a plist requires one parameter in the plist is called ''key'''); | |
102 end | |
103 if isempty(pl_val) | |
104 error('### building a parameter from a plist requires one parameter in the plist is called ''val'''); | |
105 end | |
106 | |
107 obj.key = pl_key; | |
108 obj.val = pl_val; | |
109 if ~isempty(pl_desc) | |
110 if ~ischar(pl_desc) | |
111 error('### The description of a parameter must be a string but it is from the class [%s]', class(pl_desc)); | |
112 end | |
113 obj.desc = pl_desc; | |
114 end | |
115 end | |
116 | |
117 elseif isstruct(varargin{1}) | |
118 %%%%%%%%%% obj = param(struct) %%%%%%%%%% | |
119 obj = fromStruct(obj, varargin{1}); | |
120 | |
121 else | |
122 error('### unknown constructor type for param object.'); | |
123 end | |
124 | |
125 case 2 | |
126 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
127 %%%%%%%%%%%%%%%%%%%%%%%%%%% two inputs %%%%%%%%%%%%%%%%%%%%%%%%%% | |
128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
129 if iscell(varargin{1}) | |
130 %%%%%%%%%% obj = param({'key', 'desc'}, ...) %%%%%%%%%% | |
131 obj.key = varargin{1}{1}; | |
132 if ischar(varargin{1}{2}); | |
133 obj.desc = varargin{1}{2}; | |
134 else | |
135 error('### The description of a parameter must be a string but it is from the class [%s]', class(varargin{1}{2})); | |
136 end | |
137 | |
138 elseif isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') | |
139 %%%%%%%%%% obj = param(DOM node, history-objects) %%%%%%%%%% | |
140 obj = fromDom(obj, varargin{1}, varargin{2}); | |
141 return | |
142 | |
143 else | |
144 %%%%%%%%%% obj = param('key', ...) %%%%%%%%%% | |
145 obj.key = varargin{1}; | |
146 end | |
147 | |
148 if iscell(varargin{2}) && ... | |
149 numel(varargin{2}) == 3 && ... | |
150 isnumeric(varargin{2}{1}) && ... | |
151 iscell(varargin{2}{2}) && ... | |
152 isnumeric(varargin{2}{3}) | |
153 %%%%%%%%%% obj = param(..., {idx2options, {options}, selectionMode}) %%%%%%%%%% | |
154 %%%%%%%%%% example: param(..., {1, {1 2 3}, 0}) %%%%%%%%%% | |
155 %%%%%%%%%% example: param(..., {1, {'a' 'b' 'c'}, 0}) %%%%%%%%%% | |
156 obj.val = paramValue(varargin{2}{1}, varargin{2}{2}, varargin{2}{3}); | |
157 | |
158 else | |
159 obj.val = varargin{2}; | |
160 end | |
161 | |
162 case 3 | |
163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
164 %%%%%%%%%%%%%%%%%%%%%%%%%% three inputs %%%%%%%%%%%%%%%%%%%%%%%%% | |
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
166 obj.key = varargin{1}; | |
167 obj.val = varargin{2}; | |
168 if ischar(varargin{3}) | |
169 obj.desc = varargin{3}; | |
170 else | |
171 error('### The description of a parameter must be a string but it is from the class [%s]', class(varargin{1}{2})); | |
172 end | |
173 | |
174 otherwise | |
175 error('### Unknown number of arguments.'); | |
176 end | |
177 | |
178 end | |
179 end | |
180 | |
181 | |
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
183 % Methods (public) % | |
184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
185 | |
186 methods | |
187 varargout = mux(varargin); | |
188 varargout = string(varargin) | |
189 | |
190 %%% Define Abstract methods | |
191 varargout = char(varargin) | |
192 varargout = copy(varargin) | |
193 varargout = display(varargin) | |
194 | |
195 varargout = setKey(varargin) | |
196 varargout = setVal(varargin) | |
197 varargout = setDesc(varargin) | |
198 varargout = setKeyVal(varargin) | |
199 | |
200 varargout = getVal(varargin) | |
201 varargout = getDefaultVal(varargin) | |
202 varargout = getOptions(varargin) | |
203 | |
204 varargout = setProperty(varargin) | |
205 varargout = getProperty(varargin) | |
206 | |
207 p = setDefaultOption(p, option) | |
208 p = setDefaultIndex(p, index) | |
209 end | |
210 | |
211 methods (Hidden = true) | |
212 varargout = attachToDom(varargin) | |
213 end | |
214 | |
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
216 % Methods (protected) % | |
217 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
218 | |
219 methods (Access = protected) | |
220 varargout = fromStruct(varargin) | |
221 varargout = fromDom(varargin) | |
222 end | |
223 | |
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
225 % Methods (private) % | |
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
227 | |
228 methods (Access = private) | |
229 end | |
230 | |
231 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
232 % Methods (Static, Public) % | |
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
234 | |
235 methods (Static = true) | |
236 | |
237 function out = VEROUT() | |
238 out = '$Id: param.m,v 1.72 2011/03/28 17:02:28 ingo Exp $'; | |
239 end | |
240 | |
241 function ii = getInfo(varargin) | |
242 ii = utils.helper.generic_getInfo(varargin{:}, 'param'); | |
243 end | |
244 | |
245 function out = SETS() | |
246 out = {'Default'}; | |
247 end | |
248 | |
249 function out = getDefaultPlist(set) | |
250 switch lower(set) | |
251 case 'default' | |
252 out = plist(); | |
253 otherwise | |
254 error('### Unknown set [%s]', set'); | |
255 end | |
256 end | |
257 | |
258 function obj = initObjectWithSize(n,m) | |
259 obj = param.newarray([n m]); | |
260 end | |
261 | |
262 end | |
263 | |
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
265 % Methods (Static, Private) % | |
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
267 | |
268 methods (Static = true, Access = private) | |
269 end | |
270 | |
271 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
272 % Methods (static, hidden) % | |
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
274 | |
275 methods (Static = true, Hidden = true) | |
276 varargout = loadobj(varargin) | |
277 varargout = update_struct(varargin) | |
278 end | |
279 | |
280 end | |
281 |