Home > classes > @plist > append.m

append

PURPOSE ^

APPEND append a param-object, plist-object or a key/value pair to the parameter list.

SYNOPSIS ^

function varargout = append(varargin)

DESCRIPTION ^

 APPEND append a param-object, plist-object or a key/value pair to the parameter list.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: APPEND append a param-object, plist-object or a key/value pair to
              the parameter list.

 CALL:        pl = append(pl, param-object);
              pl = append(pl, plist-object);
              pl = append(pl, 'key1', 'value1');

              pl = append(pl, combination of the examples above)

 REMARK:      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.

 M-FILE INFO: Get information about this methods by calling
              >> plist.getInfo('append')

              Get information about a specified set-plist by calling:
              >> plist.getInfo('append', 'set')

 VERSION:     $Id: append.m,v 1.17 2008/09/04 15:29:31 ingo Exp $

 HISTORY:     30-01-07 M Hewitson
                Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % APPEND append a param-object, plist-object or a key/value pair to the parameter list.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: APPEND append a param-object, plist-object or a key/value pair to
0005 %              the parameter list.
0006 %
0007 % CALL:        pl = append(pl, param-object);
0008 %              pl = append(pl, plist-object);
0009 %              pl = append(pl, 'key1', 'value1');
0010 %
0011 %              pl = append(pl, combination of the examples above)
0012 %
0013 % REMARK:      It is not possible to append an key/value pair if the key exist
0014 %              in the parameter list. Tn this case an error is thrown.
0015 %
0016 % M-FILE INFO: Get information about this methods by calling
0017 %              >> plist.getInfo('append')
0018 %
0019 %              Get information about a specified set-plist by calling:
0020 %              >> plist.getInfo('append', 'set')
0021 %
0022 % VERSION:     $Id: append.m,v 1.17 2008/09/04 15:29:31 ingo Exp $
0023 %
0024 % HISTORY:     30-01-07 M Hewitson
0025 %                Creation
0026 %
0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0028 
0029 function varargout = append(varargin)
0030 
0031   import utils.const.*
0032 
0033   %%% Check if this is a call for parameters
0034   if utils.helper.isinfocall(varargin{:})
0035     varargout{1} = getInfo(varargin{3});
0036     return
0037   end
0038 
0039   utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
0040 
0041   [objs, invars, rest] = utils.helper.collect_objects(varargin(:), 'plist');
0042   [pps,  invars, rest] = utils.helper.collect_objects(rest(:), 'param');
0043 
0044   %%% Decide on a deep copy or a modify
0045   pls = copy(objs, nargout);
0046 
0047   %%% REMARK: If the rest is an single string and the number of plist is two
0048   %%%         then we assume that the rest and the second plist are a key/value
0049   %%%         pair.
0050   if numel(rest) == 1 && ischar(rest{1}) && numel(objs) == 2
0051     rest{2} = objs(2);
0052     pls(2) = [];
0053   end
0054 
0055   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0056   %%%%%%%%%%             First Case: Append plist-objects              %%%%%%%%%%
0057   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0058 
0059   pl = pls(1);
0060 
0061   %%% If we found more than one plist then append the parameters
0062   %%% of the second, third, ... plist to the first plist
0063   if numel (pls) > 1
0064     for kk = 2:numel(pls)
0065       for jj = 1:length(pls(kk).params)
0066         add_param(pl, pls(kk).params(jj));
0067       end
0068     end
0069   end
0070 
0071   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0072   %%%%%%%%%%             Second Case: Append param-objects             %%%%%%%%%%
0073   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0074 
0075   if ~isempty(pps)
0076     for kk = 1:numel(pps)
0077       add_param(pl, pps(kk));
0078     end
0079   end
0080 
0081   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0082   %%%%%%%%%%             Third Case: Append key/value pairs            %%%%%%%%%%
0083   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0084 
0085   if ~isempty(rest)
0086     if mod(numel(rest),2) ~= 0
0087       error('### Please define a ''key'' AND a ''value''%s### to append this pair.', char(10));
0088     end
0089     while ~isempty(rest)
0090       key = rest{1};
0091       val = rest{2};
0092 
0093       %%% Remove the first two objects from the 'rest' variable
0094       rest(1) = [];
0095       rest(1) = [];
0096 
0097       add_param(pl, param(key,val));
0098     end
0099   end
0100 
0101   varargout{1} = pl;
0102 end
0103 
0104 
0105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0106 %                               Local Functions                               %
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 
0109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0110 % DESCRIPTION: The input parameter will only be added if the key doesn't exist
0111 %              in the plist. Throw an error if the key exist in the plist.
0112 function add_param(pl, pp)
0113 
0114 
0115   for ii = 1:length(pl.params)
0116     if strcmpi(pl.params(ii).key, pp.key)
0117       error('\n### The key [%s] exist in the parameter list.\n### Please use the function pset.',pp.key);
0118       % pl.params(ii).val = param.val;
0119       return
0120     end
0121   end
0122 
0123   utils.helper.msg(utils.const.msg.OPROC1, 'appending parameter %s', pp.key);
0124 
0125   % Convert all key characters into upper case characters
0126   pp.setKey(upper(pp.key));
0127   pl.params = [pl.params pp];
0128 end
0129 
0130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0131 %
0132 % FUNCTION:    getInfo
0133 %
0134 % DESCRIPTION: Get Info Object
0135 %
0136 % HISTORY:     11-07-07 M Hewitson
0137 %                Creation.
0138 %
0139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0140 
0141 function ii = getInfo(varargin)
0142   if nargin == 1 && strcmpi(varargin{1}, 'None')
0143     sets = {};
0144     pl   = [];
0145   else
0146     sets = {'Default'};
0147     pl   = getDefaultPlist;
0148   end
0149   % Build info object
0150   ii = minfo(mfilename, 'plist', '', utils.const.categories.helper, '$Id: append.m,v 1.17 2008/09/04 15:29:31 ingo Exp $', sets, pl);
0151 end
0152 
0153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0154 %
0155 % FUNCTION:    getDefaultPlist
0156 %
0157 % DESCRIPTION: Get Default Plist
0158 %
0159 % HISTORY:     11-07-07 M Hewitson
0160 %                Creation.
0161 %
0162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0163 
0164 function plo = getDefaultPlist()
0165   plo = plist();
0166 end
0167

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003