Mercurial > hg > ltpda
comparison m-toolbox/classes/@ltpda_uoh/setProperties.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 % SETPROPERTIES set different properties of an object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: set different properties of an object. It is possible to define | |
5 % the property/value pairs in a plist or direct as the input. | |
6 % | |
7 % CALL: obj = setProperties(obj, 'prop1', val1, 'prop2', val2); | |
8 % obj = setProperties(obj, pl); | |
9 % | |
10 % VERSION: $Id: setProperties.m,v 1.18 2011/07/07 11:05:31 mauro Exp $ | |
11 % | |
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
13 | |
14 function varargout = setProperties(varargin) | |
15 | |
16 % Collect all user objects with history | |
17 [objs, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ltpda_uoh'); | |
18 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
19 | |
20 if numel(pl) > 0 && numel(rest) > 0 | |
21 error('### I Don''t know what do do. If a parameter should contain a plist then specify the property and the value in a plist'); | |
22 end | |
23 | |
24 % Decide on a deep copy or a modify | |
25 objs = copy(objs, nargout); | |
26 | |
27 % Combine the rest of the inputs to the plist | |
28 while length(rest) >= 2 | |
29 prop = upper(rest{1}); | |
30 val = rest{2}; | |
31 rest = rest(3:end); | |
32 | |
33 if ischar(prop) | |
34 pl = combine(plist(prop, val), pl); | |
35 else | |
36 error('### The input property must be a char but it is a [%s] object', class(prop)); | |
37 end | |
38 end | |
39 | |
40 for ii = 1:numel(objs) | |
41 | |
42 obj_class = class(objs(ii)); | |
43 mthds = methods(obj_class); | |
44 | |
45 for jj = 1:pl.nparams | |
46 | |
47 cmd = ['set' pl.params(jj).key(1) lower(pl.params(jj).key(2:end))]; | |
48 | |
49 % Special case for the timespan class because the set methos for the | |
50 % 'startT' and 'endT' properties ends with a capital letter | |
51 if isa(objs, 'timespan') && ... | |
52 (strcmpi(pl.params(jj).key, 'endT') ||... | |
53 strcmpi(pl.params(jj).key, 'startT')) | |
54 cmd(end) = 'T'; | |
55 end | |
56 | |
57 if utils.helper.ismember(cmd, mthds) | |
58 %%%%%%%%%% It exists a set method to set the property %%%%%%%%%% | |
59 try | |
60 if iscell(pl.params(jj).getVal) && length(pl.params(jj).getVal) == length(objs) | |
61 %%% Set the value in the cell | |
62 feval(cmd, objs(ii), pl.params(jj).getVal{ii}); | |
63 %%% Reset the value in the plistUset to this single value | |
64 objs(ii).hist.plistUsed.pset(pl.params(jj).key, pl.params(jj).getVal{ii}); | |
65 else | |
66 %%% Set the value | |
67 feval(cmd, objs(ii), pl.params(jj).getVal); | |
68 end | |
69 %%% Deprecation warning | |
70 warning('!!! Setting property ''%s'' which is not in the default plist is now deprecated and will be removed in future versions. Please use dedicated setter methods', ... | |
71 pl.params(jj).key); | |
72 catch ME | |
73 fprintf(2, '%s\n\n', ME.message); | |
74 warning(utils.const.warnings.METHOD_NOT_FOUND, '!!! Can not set the the property [%s] because the setter-method fails.', lower(pl.params(jj).key)); | |
75 end | |
76 elseif objs(ii).isprop(lower(pl.params(jj).key)) | |
77 warning(utils.const.warnings.METHOD_NOT_FOUND, '!!! The Object has the property [%s] but there doesn''t exist a public set method', lower(pl.params(jj).key)); | |
78 end | |
79 | |
80 end % End loop over params | |
81 | |
82 end % for-loop over all objects | |
83 | |
84 % Set output | |
85 varargout = utils.helper.setoutputs(nargout, objs); | |
86 | |
87 end |