Home > classes > @param > setKey.m

setKey

PURPOSE ^

SETKEY Set the property 'key'.

SYNOPSIS ^

function varargout = setKey(varargin)

DESCRIPTION ^

 SETKEY Set the property 'key'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: Set the property 'key'.

 CALL:        obj = obj.setKey('new key');
              obj = obj.setKey(plist('key', 'new key'));
              obj = setKey(obj, 'new key');

 INPUTS:      obj - can be a vector, matrix, list, or a mix of them.
              pl  - to set the key with a plist specify only one plist with
                    only one key-word 'key'.

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

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

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

 HISTORY:     27-05-2008 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % SETKEY Set the property 'key'.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: Set the property 'key'.
0005 %
0006 % CALL:        obj = obj.setKey('new key');
0007 %              obj = obj.setKey(plist('key', 'new key'));
0008 %              obj = setKey(obj, 'new key');
0009 %
0010 % INPUTS:      obj - can be a vector, matrix, list, or a mix of them.
0011 %              pl  - to set the key with a plist specify only one plist with
0012 %                    only one key-word 'key'.
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> param.getInfo('setKey')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> param.getInfo('setKey', 'set')
0019 %
0020 % VERSION:     $Id: setKey.m,v 1.6 2008/09/04 15:29:31 ingo Exp $
0021 %
0022 % HISTORY:     27-05-2008 Diepholz
0023 %                 Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = setKey(varargin)
0028 
0029   %%% Check if this is a call for parameters
0030   if utils.helper.isinfocall(varargin{:})
0031     varargout{1} = getInfo(varargin{3});
0032     return
0033   end
0034 
0035   %%% Internal call: Only one object + don't look for a plist
0036   if strcmp(varargin{end}, 'internal')
0037 
0038     %%% decide whether we modify the first plist, or create a new one.
0039     varargin{1} = copy(varargin{1}, nargout);
0040 
0041     varargin{1}.key = varargin{2};
0042     varargout{1} = varargin{1};
0043     return
0044   end
0045 
0046   [objs, invars, rest] = utils.helper.collect_objects(varargin(:), 'param');
0047   [pls,  invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
0048 
0049   vals = rest;
0050 
0051   if length(vals) ~=1
0052 
0053     if length(pls) == 1
0054       vals = {};
0055       if nparams(pls) == 1 && isparam(pls, 'key')
0056 
0057         %%% If the plist contains only one parameter with the key-word 'key'
0058         %%% then set 'key' to the value in the plist
0059         vals{1} = find(pls(1), 'key');
0060 
0061       else
0062         vals{1} = pls;
0063       end
0064     elseif length(pls) > 1
0065       error('### To set the ''key'' please specify only one plist')
0066     else
0067       error('### Please specify [only one] key.')
0068     end
0069   end
0070 
0071   %%% Set the Key
0072   for ii = 1:numel(objs)
0073 
0074     %%% decide whether we modify the first plist, or create a new one.
0075     objs(ii) = copy(objs(ii), nargout);
0076 
0077     objs(ii).key = vals{1};
0078   end
0079 
0080   %%% Prepare output
0081   varargout{1} = objs;
0082 
0083 end
0084 
0085 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0086 %                               Local Functions                               %
0087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0088 
0089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0090 %
0091 % FUNCTION:    getInfo
0092 %
0093 % DESCRIPTION: Get Info Object
0094 %
0095 % HISTORY:     11-07-07 M Hewitson
0096 %                Creation.
0097 %
0098 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0099 
0100 function ii = getInfo(varargin)
0101   if nargin == 1 && strcmpi(varargin{1}, 'None')
0102     sets = {};
0103     pl   = [];
0104   else
0105     sets = {'Default'};
0106     pl   = getDefaultPlist;
0107   end
0108   % Build info object
0109   ii = minfo(mfilename, 'param', '', utils.const.categories.internal, '$Id: setKey.m,v 1.6 2008/09/04 15:29:31 ingo Exp $', sets, pl);
0110 end
0111 
0112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0113 %
0114 % FUNCTION:    getDefaultPlist
0115 %
0116 % DESCRIPTION: Get Default Plist
0117 %
0118 % HISTORY:     11-07-07 M Hewitson
0119 %                Creation.
0120 %
0121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0122 
0123 function plo = getDefaultPlist()
0124   plo = plist('key', '');
0125 end
0126

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