Home > classes > @plist > append.m

append

PURPOSE ^

APPEND append a parameter to the parameter list.

SYNOPSIS ^

function pl = append(pl, varargin)

DESCRIPTION ^

 APPEND append a parameter to the parameter list.

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

 DESCRIPTION: APPEND append a parameter to the parameter list.

 CALL:        pl = append(pl,p);
              pl = append(pl,pl);
              pl = append(pl, 'key1', 'value1')

 REMAKR:      It is not possible to append an key/value pair if the key exist
              in the parameter list. Tn this case an error is thrown.

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

 HISTORY:     30-01-07 M Hewitson
                Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function pl = append(pl, varargin)
0002 % APPEND append a parameter to the parameter list.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: APPEND append a parameter to the parameter list.
0007 %
0008 % CALL:        pl = append(pl,p);
0009 %              pl = append(pl,pl);
0010 %              pl = append(pl, 'key1', 'value1')
0011 %
0012 % REMAKR:      It is not possible to append an key/value pair if the key exist
0013 %              in the parameter list. Tn this case an error is thrown.
0014 %
0015 % VERSION:     $Id: append.m,v 1.7 2007/12/11 19:31:02 ingo Exp $
0016 %
0017 % HISTORY:     30-01-07 M Hewitson
0018 %                Creation
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 
0022 VERSION  = '$Id: append.m,v 1.7 2007/12/11 19:31:02 ingo Exp $';
0023 
0024 % Check if this is a call for parameters
0025 if nargin == 2
0026   if isa(pl, 'plist') && ischar(varargin{1})
0027     in = char(varargin{1});
0028     if strcmp(in, 'Params')
0029       pl = plist();
0030       return
0031     elseif strcmp(in, 'Version')
0032       pl = VERSION;
0033       return
0034     end
0035   end
0036 end
0037 
0038 argin  = varargin;
0039 
0040 while ~isempty(argin)
0041 
0042   if isa(argin{1}, 'param')
0043     pp = argin{1};
0044     pl = add_param(pl, pp);
0045     argin = argin(2:end);
0046 
0047   elseif isa(argin{1}, 'plist')
0048     pl_in = argin{1};
0049 
0050     for ii = 1:nparams(pl_in)
0051       pl = add_param(pl, pl_in.params(ii));
0052     end
0053     argin = argin(2:end);
0054 
0055   else
0056     if length(argin) >= 2
0057       key = argin{1};
0058       val = argin{2};
0059       pl = add_param(pl, param(key, val));
0060       argin = argin(3:end);
0061     else
0062       error('### There is a key [%s] without a value left.', key);
0063       argin = argin(2:end);
0064     end
0065   end
0066 end
0067 
0068 
0069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0070 %
0071 % DESCRIPTION: The input parameter will only be added if the key doesn't exist
0072 %              in the plist. Throw an error if the key exist in the plist.
0073 %
0074 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0075 function pl = add_param(pl, param)
0076 
0077 for ii = 1:nparams(pl)
0078   if strcmpi(pl.params(ii).key, param.key)
0079     error('### The key [%s] exist in the parameter list.\n\n### Please use the function pset.',param.key);
0080     % pl.params(ii).val = param.val;
0081     return
0082   end
0083 end
0084 
0085 % Convert all key characters into upper case characters
0086 param.key = upper(param.key);
0087 
0088 pl.params = [pl.params param];
0089 
0090 % END
0091

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