Home > classes > @ltpda_uo > setName.m

setName

PURPOSE ^

SETNAME Set the property 'name'.

SYNOPSIS ^

function varargout = setName(varargin)

DESCRIPTION ^

 SETNAME Set the property 'name'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: Set the property 'name'.

 CALL:        obj = obj.setName('new name');
              obj = obj.setName(plist('name', 'new name'));
              obj = setName(obj, 'new name');

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

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

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

 VERSION:     $Id: setName.m,v 1.11 2008/09/04 15:29:30 ingo Exp $

 HISTORY:     27-05-2008 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % SETNAME Set the property 'name'.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: Set the property 'name'.
0005 %
0006 % CALL:        obj = obj.setName('new name');
0007 %              obj = obj.setName(plist('name', 'new name'));
0008 %              obj = setName(obj, 'new name');
0009 %
0010 % INPUTS:      obj - can be a vector, matrix, list, or a mix of them.
0011 %              pl  - to set the name with a plist specify only one plist with
0012 %                    only one key-word 'name'.
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> ao.getInfo('setName')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> ao.getInfo('setName', 'set')
0019 %
0020 % VERSION:     $Id: setName.m,v 1.11 2008/09/04 15:29:30 ingo Exp $
0021 %
0022 % HISTORY:     27-05-2008 Diepholz
0023 %                 Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = setName(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 object, or create a new one.
0039     varargin{1} = copy(varargin{1}, nargout);
0040 
0041     varargin{1}.name = varargin{2};
0042     varargout{1} = varargin{1};
0043     return
0044   end
0045 
0046   %%% Collect input variable names
0047   in_names = cell(size(varargin));
0048   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0049 
0050   [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), '', in_names);
0051   [pls,  invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
0052 
0053   %%% REMARK: Special case for the plist-class because collect_objects collects
0054   %%%         ALL plist-objects even the plist which should set the property.
0055   %%%         In this case must be the plist which sets thte property
0056   %%%         at the last position.
0057   if isa(objs, 'plist')
0058     if nparams(objs(end)) == 1 && isparam(objs(end), 'name')
0059       pls = [pls objs(end)];
0060       objs(end)   = [];
0061     end
0062   end
0063   
0064   %%% If pls contains only one plist with the only key 'name' then set the
0065   %%% property with a plist.
0066   if length(pls) == 1 && isa(pls, 'plist') && nparams(pls) == 1 && isparam(pls, 'name')
0067     rest{1} = find(pls, 'name');
0068   end
0069 
0070   if numel(rest) > 1
0071     error('### Please specify a single name, either in a plist or directly.');
0072   end
0073   if ~ischar(rest)
0074     error('### The name must be a string');
0075   end
0076   
0077   %%% If rest is not filled then use the variable name for the property.
0078   if isempty(rest)
0079     vals = in_names{1};
0080   else
0081     vals = rest{1};
0082   end
0083 
0084   %%%
0085   pls = combine(pls, plist('name', vals));
0086 
0087   %%% Restrict name length
0088   if length(vals) > 35
0089     vals = [vals(1:20) '...' vals(end-12:end)];
0090   end
0091 
0092   %%% Set the Name
0093   for ii = 1:numel(objs)
0094 
0095     %%% decide whether we modify the first plist, or create a new one.
0096     objs(ii) = copy(objs(ii), nargout);
0097 
0098     %%% set the value
0099     objs(ii).name = vals;
0100   end
0101 
0102   %%% Prepare output
0103   varargout{1} = objs;
0104 end
0105 
0106 
0107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0108 %                               Local Functions                               %
0109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0110 
0111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0112 %
0113 % FUNCTION:    getInfo
0114 %
0115 % DESCRIPTION: Get Info Object
0116 %
0117 % HISTORY:     11-07-07 M Hewitson
0118 %                Creation.
0119 %
0120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0121 
0122 function ii = getInfo(varargin)
0123   if nargin == 1 && strcmpi(varargin{1}, 'None')
0124     sets = {};
0125     pl   = [];
0126   else
0127     sets = {'Default'};
0128     pl   = getDefaultPlist;
0129   end
0130   % Build info object
0131   ii = minfo(mfilename, 'ltpda_uo', '', utils.const.categories.helper, '$Id: setName.m,v 1.11 2008/09/04 15:29:30 ingo Exp $', sets, pl);
0132 end
0133 
0134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0135 %
0136 % FUNCTION:    getDefaultPlist
0137 %
0138 % DESCRIPTION: Get Default Plist
0139 %
0140 % HISTORY:     11-07-07 M Hewitson
0141 %                Creation.
0142 %
0143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0144 
0145 function plo = getDefaultPlist()
0146   plo = plist('name', '');
0147 end
0148

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