Mercurial > hg > ltpda
comparison m-toolbox/classes/@smodel/setAliases.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 % SETALIASES Set the key-value pairs to the alias-names and alias-values | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETALIASES Set the key-value pairs to the alias-names and | |
5 % alias-values. This method will set the key-value pairs to | |
6 % the properties 'aliasNames' and 'aliasValues'. This method | |
7 % will not keep the existing aliases. | |
8 % | |
9 % CALL: obj = obj.setAliases('name', 'value'); | |
10 % obj = obj.setAliases(key-value pairs); | |
11 % obj = obj.setAliases(plist); | |
12 % obj = obj.setAliases(two cell-arrays); | |
13 % | |
14 % INPUTS: obj - a ltpda smodel object. | |
15 % key-value - A single key-value pair or a list of key-value | |
16 % pairs. Thereby it is important that the key is | |
17 % followed by the value. | |
18 % plist - Parameter list with values for the keys | |
19 % 'names' and 'values'. The values can be a | |
20 % single value or a cell array with multiple | |
21 % values. The number of 'names' and 'values' | |
22 % must be the same. | |
23 % cell-arrays - Two cell-arrays with the first of the 'names' | |
24 % and the second with the 'values'. | |
25 % | |
26 % <a href="matlab:utils.helper.displayMethodInfo('smodel', 'setAliases')">Parameters Description</a> | |
27 % | |
28 % VERSION: $Id: setAliases.m,v 1.2 2011/04/28 19:50:57 mauro Exp $ | |
29 % | |
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
31 | |
32 function varargout = setAliases(varargin) | |
33 | |
34 % Check if this is a call from a class method | |
35 callerIsMethod = utils.helper.callerIsMethod; | |
36 | |
37 if callerIsMethod | |
38 sm = varargin{1}; % smodel-object(s) | |
39 names = varargin{2}; % cell-array with alias-names | |
40 values = varargin{3}; % call-array with alias-values | |
41 | |
42 else | |
43 % Check if this is a call for parameters | |
44 if utils.helper.isinfocall(varargin{:}) | |
45 varargout{1} = getInfo(varargin{3}); | |
46 return | |
47 end | |
48 | |
49 import utils.const.* | |
50 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
51 | |
52 % Collect input variable names | |
53 in_names = cell(size(varargin)); | |
54 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
55 | |
56 % Collect all smodel objects | |
57 [sm, sm_invars, rest] = utils.helper.collect_objects(varargin(:), 'smodel', in_names); | |
58 [pls, dummy, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
59 | |
60 names = {}; | |
61 values = {}; | |
62 %%% If the input PLIST have the keys 'names' and 'values' then use also | |
63 %%% the | |
64 if length(pls) == 1 && isa(pls, 'plist') && isparam(pls, 'names') && isparam(pls, 'values') | |
65 names = find(pls, 'names'); | |
66 values = find(pls, 'values'); | |
67 | |
68 % Make sure that the names and the values are cell-arrays | |
69 if ~iscell(names) | |
70 names = cellstr(names); | |
71 end | |
72 if ~iscell(values) | |
73 values = num2cell(values); | |
74 end | |
75 | |
76 end | |
77 | |
78 % Check if we have two cell-array for the 'names' and 'values' | |
79 if numel(rest) == 2 && iscell(rest{1}) && iscell(rest{2}) | |
80 names = [names rest{1}]; | |
81 values = [values rest{2}]; | |
82 else | |
83 | |
84 % Check for key-value pairs | |
85 if mod(numel(rest), 2) ~= 0 | |
86 error('### Please specify for each alias-name a alias-value'); | |
87 end | |
88 nrest = numel(rest); | |
89 names = [names rest(1:2:nrest)]; | |
90 values = [values rest(2:2:nrest)]; | |
91 end | |
92 | |
93 % Combine input plists and default PLIST | |
94 pls = combine(pls, getDefaultPlist()); | |
95 | |
96 end | |
97 | |
98 % Check that we have the same number of names as the number of values. | |
99 if numel(names) ~= numel(values) | |
100 error('### Please specify for each alias name [%d] one alias value [%d]', numel(names), numel(values)); | |
101 end | |
102 | |
103 % Decide on a deep copy or a modify | |
104 sm = copy(sm, nargout); | |
105 | |
106 % Loop over smodel objects | |
107 for jj = 1:numel(sm) | |
108 | |
109 % Append the alias key-value pair | |
110 sm(jj).aliasNames = names; | |
111 sm(jj).aliasValues = values; | |
112 | |
113 if ~callerIsMethod | |
114 plh = pls.pset('names', names); | |
115 plh.pset('values', values); | |
116 sm(jj).addHistory(getInfo('None'), plh, sm_invars(jj), sm(jj).hist); | |
117 end | |
118 end | |
119 | |
120 % Set output | |
121 varargout = utils.helper.setoutputs(nargout, sm); | |
122 end | |
123 | |
124 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
125 % | |
126 % FUNCTION: getInfo | |
127 % | |
128 % DESCRIPTION: Get Info Object | |
129 % | |
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
131 | |
132 function ii = getInfo(varargin) | |
133 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
134 sets = {}; | |
135 pl = []; | |
136 else | |
137 sets = {'Default'}; | |
138 pl = getDefaultPlist(); | |
139 end | |
140 % Build info object | |
141 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setAliases.m,v 1.2 2011/04/28 19:50:57 mauro Exp $', sets, pl); | |
142 end | |
143 | |
144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
145 % | |
146 % FUNCTION: getDefaultPlist | |
147 % | |
148 % DESCRIPTION: Get Default Plist | |
149 % | |
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
151 | |
152 function plout = getDefaultPlist() | |
153 persistent pl; | |
154 if ~exist('pl', 'var') || isempty(pl) | |
155 pl = buildplist(); | |
156 end | |
157 plout = pl; | |
158 end | |
159 | |
160 function pl = buildplist() | |
161 pl = plist(); | |
162 | |
163 % alias names | |
164 p = param({'names', 'A cell-array with the alias names.'}, paramValue.EMPTY_CELL); | |
165 pl.append(p); | |
166 | |
167 % alias values | |
168 p = param({'values', 'A cell-array with the alias values.'}, paramValue.EMPTY_CELL); | |
169 pl.append(p); | |
170 end | |
171 |