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