Mercurial > hg > ltpda
comparison m-toolbox/classes/@ltpda_uo/setPropertyValue.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 % SETPROPERTYVALUE sets the value of a property of one or more objects. | |
2 % | |
3 % CALL: | |
4 % varargout = setPropertyValue(inputs, ... | |
5 % input_names, ... | |
6 % callerIsMethod, ... | |
7 % propName, ... | |
8 % setterFcn, ... | |
9 % copy, ... | |
10 % getInfo) | |
11 % | |
12 % | |
13 % | |
14 % | |
15 % | |
16 % The setterFcn should have the following signature: | |
17 % | |
18 % setterFcn(object, plist, value) | |
19 % | |
20 % The plist is passed to allow the setter function to modify the plist if | |
21 % necessary. | |
22 % | |
23 % | |
24 function varargout = setPropertyValue(varargin) | |
25 | |
26 % get inputs | |
27 inputs = varargin(1:end-6); | |
28 input_names = varargin{end-5}; | |
29 callerIsMethod = varargin{end-4}; | |
30 propName = varargin{end-3}; | |
31 setterFcn = varargin{end-2}; | |
32 doCopy = varargin{end-1}; | |
33 getInfo = varargin{end}; | |
34 | |
35 % Check if this is a call for parameters | |
36 if utils.helper.isinfocall(varargin{1:end-6}) | |
37 varargout{1} = getInfo(varargin{3}); | |
38 return | |
39 end | |
40 | |
41 % Collect inputs | |
42 if callerIsMethod | |
43 objects = inputs{1}; | |
44 pls = []; | |
45 rest = inputs(2:end); | |
46 obj_invars = {}; | |
47 else | |
48 [objects, obj_invars, rest] = utils.helper.collect_objects(inputs(:), '', input_names); | |
49 [pls, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
50 % Copy the user input plists because they may be modified in the setter | |
51 % functions. | |
52 if ~isempty(pls) | |
53 pls = copy(pls, 1); | |
54 end | |
55 end | |
56 | |
57 % Process the values we want to set | |
58 [objects, values] = processSetterValues(objects, pls, rest, propName); | |
59 | |
60 % Decide on a deep copy or a modify | |
61 bs = copy(objects, doCopy); | |
62 | |
63 usedValues = cell(size(bs)); | |
64 if isempty(setterFcn) | |
65 | |
66 if isempty(values) | |
67 error('Please provide a value for the property ''%s''', propName); | |
68 end | |
69 | |
70 for jj=1:numel(bs) | |
71 usedValues{jj} = defaultSetter(bs(jj), values{jj}, propName); | |
72 end | |
73 | |
74 else | |
75 % Loop over objects and set the values by calling the setter function | |
76 for jj = 1:numel(bs) | |
77 if isempty(values) | |
78 if isempty(pls) | |
79 % here we create a plist so that the setterFcn has a plist in | |
80 % case it wants to modify it before it goes in the history. | |
81 pls = plist(); | |
82 end | |
83 usedValues{jj} = setterFcn(bs(jj), pls); | |
84 else | |
85 usedValues{jj} = setterFcn(bs(jj), pls, values{jj}); | |
86 end | |
87 end | |
88 end | |
89 | |
90 | |
91 % Set output | |
92 varargout{1} = bs; | |
93 if nargout > 1 | |
94 varargout{2} = usedValues; | |
95 end | |
96 if nargout > 2 | |
97 varargout{3} = pls; | |
98 end | |
99 if nargout > 3 | |
100 varargout{4} = obj_invars; | |
101 end | |
102 | |
103 end | |
104 % END | |
105 | |
106 % Default setter function to set the description | |
107 % | |
108 % defaultSetter(obj, value, propertyName) | |
109 % | |
110 function value = defaultSetter(varargin) | |
111 | |
112 obj = varargin{1}; | |
113 value = varargin{2}; | |
114 propName = varargin{3}; | |
115 | |
116 % TODO: we could check the type of value here against the default/defined value | |
117 | |
118 obj.(propName) = value; | |
119 | |
120 end |