comparison m-toolbox/classes/@plist/combine.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 % COMBINE multiple parameter lists (plist objects) into a single plist.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: COMBINE multiple parameter lists (plist objects) into a single
5 % plist. Duplicate parameters are given priority in the order
6 % in which they appear in the input.
7 %
8 % CALL: pl = combine(p1, p2, p3);
9 % pl = combine(p1, [p2 p3], p4)
10 %
11 % EXAMPLES: >> pl1 = plist('A', 1);
12 % >> pl2 = plist('A', 3);
13 % >> plo = plist(pl1, pl2)
14 %
15 % Then plo will contain a parameter 'A' with value 1.
16 %
17 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'combine')">Parameters Description</a>
18 %
19 % VERSION: $Id: combine.m,v 1.26 2011/04/08 08:56:21 hewitson Exp $
20 %
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22
23 function varargout = combine(varargin)
24
25 %%% Check if this is a call for parameters
26 if utils.helper.isinfocall(varargin{:})
27 varargout{1} = getInfo(varargin{3});
28 return
29 end
30
31 objs = utils.helper.collect_objects(varargin(:), 'plist');
32
33 %%% decide whether we modify the first plist, or create a new one.
34 pl = copy(objs(1), nargout);
35 changed = false;
36
37 %%% If we found more than one plist then append the parameters
38 %%% of the second, third, ... plist to the first plist
39 if numel (objs) > 1
40 for ii = 2:numel(objs)
41 % Loop over all params in the current plist
42 for jj = 1:length(objs(ii).params)
43 ps = copy(objs(ii).params(jj), 1);
44 [pl, changed] = add_param(pl, ps);
45 end
46 end
47 end
48
49 varargout{1} = pl;
50 end
51
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 % Local Functions %
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 % DESCRIPTION: The input parameter will only be added if the key doesn't exist
58 % in the plist.
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 function [pl, changed] = add_param(pl, p)
61
62 if ~isempty(pl.params) && any(strcmpi({pl.params(:).key}, p.key))
63 changed = false;
64 return
65 end
66
67 changed = true;
68
69 pl.params = [pl.params p];
70 end
71
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %
74 % FUNCTION: getInfo
75 %
76 % DESCRIPTION: Get Info Object
77 %
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 function ii = getInfo(varargin)
81 if nargin == 1 && strcmpi(varargin{1}, 'None')
82 sets = {};
83 pl = [];
84 else
85 sets = {'Default'};
86 pl = getDefaultPlist;
87 end
88 % Build info object
89 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: combine.m,v 1.26 2011/04/08 08:56:21 hewitson Exp $', sets, pl);
90 ii.setArgsmin(2);
91 end
92
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % FUNCTION: getDefaultPlist
96 %
97 % DESCRIPTION: Get Default Plist
98 %
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100
101 function plo = getDefaultPlist()
102 plo = plist();
103 end
104