Home > classes > @plist > combine.m

combine

PURPOSE ^

COMBINE multiple parameter lists (plist objects) into a single plist.

SYNOPSIS ^

function plo = combine(varargin)

DESCRIPTION ^

 COMBINE multiple parameter lists (plist objects) into a single plist.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: COMBINE multiple parameter lists (plist objects) into a single
              plist. Duplicate parameters are given priority in the order
              in which they appear in the input.

 CALL:        pl = combine(p1, p2, p3);
              pl = combine(p1, [p2 p3], p4)

 EXAMPLES:    >> pl1 = plist(param('A', 1));
              >> pl2 = plist(param('A', 3));
              >> plo = plist(pl1, pl2)

              Then plo will contain a parameter 'A' with value 1.

 VERSION:     $Id: combine.m,v 1.7 2007/12/11 19:31:02 ingo Exp $

 HISTORY:     28-04-2007 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function plo = combine(varargin)
0002 % COMBINE multiple parameter lists (plist objects) into a single plist.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: COMBINE multiple parameter lists (plist objects) into a single
0007 %              plist. Duplicate parameters are given priority in the order
0008 %              in which they appear in the input.
0009 %
0010 % CALL:        pl = combine(p1, p2, p3);
0011 %              pl = combine(p1, [p2 p3], p4)
0012 %
0013 % EXAMPLES:    >> pl1 = plist(param('A', 1));
0014 %              >> pl2 = plist(param('A', 3));
0015 %              >> plo = plist(pl1, pl2)
0016 %
0017 %              Then plo will contain a parameter 'A' with value 1.
0018 %
0019 % VERSION:     $Id: combine.m,v 1.7 2007/12/11 19:31:02 ingo Exp $
0020 %
0021 % HISTORY:     28-04-2007 M Hewitson
0022 %                 Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 VERSION = '$Id: combine.m,v 1.7 2007/12/11 19:31:02 ingo Exp $';
0027 
0028 % Check if this is a call for parameters
0029 if nargin == 2
0030   if isa(varargin{1}, 'plist') && ischar(varargin{2})
0031     in = char(varargin{2});
0032     if strcmp(in, 'Params')
0033       plo = plist;
0034       return
0035     elseif strcmp(in, 'Version')
0036       plo = VERSION;
0037       return
0038     end
0039   end
0040 end
0041 
0042 % get input plists
0043 % this code allows for inputs of the form:
0044 % >> pl = combine([p1 p2], p, [p3 p4], p5, p6)
0045 % or some combination of that.
0046 pls = [];
0047 for j=1:length(varargin)
0048   pj = varargin{j};
0049   if isa(pj, 'plist')
0050     pj = reshape(pj, 1, []);
0051     pls = [pls pj];
0052   end
0053 end
0054 
0055 % The properties of the output plist is corresponding to the input plist
0056 plo = pls(1);
0057 
0058 % Loop over all plist's
0059 for ii = 2:length(pls)
0060 
0061   % Loop over all params in the current plist
0062   for jj = 1:length(pls(ii).params)
0063 
0064     ps = pls(ii).params(jj);
0065     plo = add_param(plo, ps);
0066 
0067   end
0068 
0069 end
0070 
0071 
0072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0073 %
0074 % DESCRIPTION: The input parameter will only be added if the key doesn't exist
0075 %              in the plist.
0076 %
0077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0078 function pl = add_param(pl, param)
0079 
0080 for ii = 1:nparams(pl)
0081   if strcmpi(pl.params(ii).key, param.key)
0082     % If the key exist in pl then do nothing, otherwise add the key value pair.
0083     return
0084   end
0085 end
0086 
0087 % Convert all key characters into upper case characters
0088 param.key = upper(param.key);
0089 
0090 pl.params = [pl.params param];
0091 
0092 
0093 % END
0094

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003