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.8 2008/08/11 16:31:36 hewitson 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.8 2008/08/11 16:31:36 hewitson 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 
0074   %%% If rest is not filled then use the variable name for the property.
0075   if isempty(rest)
0076     vals = in_names{1};
0077   else
0078     vals = rest{1};
0079   end
0080 
0081   %%%
0082   pls = combine(pls, plist('name', vals));
0083 
0084   %%% Restrict name length
0085   if length(vals) > 15
0086     vals = [vals(1:10) '...' vals(end-5:end)];
0087   end
0088 
0089   %%% Set the Name
0090   for ii = 1:numel(objs)
0091 
0092     %%% decide whether we modify the first plist, or create a new one.
0093     objs(ii) = copy(objs(ii), nargout);
0094 
0095     %%% set the value
0096     objs(ii).name = vals;
0097   end
0098 
0099   %%% Prepare output
0100   varargout{1} = objs;
0101 end
0102 
0103 
0104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0105 %                               Local Functions                               %
0106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0107 
0108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0109 %
0110 % FUNCTION:    getInfo
0111 %
0112 % DESCRIPTION: Get Info Object
0113 %
0114 % HISTORY:     11-07-07 M Hewitson
0115 %                Creation.
0116 %
0117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0118 
0119 function ii = getInfo(varargin)
0120   if nargin == 1 && strcmpi(varargin{1}, 'None')
0121     sets = {};
0122     pl   = [];
0123   else
0124     sets = {'Default'};
0125     pl   = getDefaultPlist;
0126   end
0127   % Build info object
0128   ii = minfo(mfilename, 'ltpda_uo', '', 'Helper', '$Id: setName.m,v 1.8 2008/08/11 16:31:36 hewitson Exp $', sets, pl);
0129 end
0130 
0131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0132 %
0133 % FUNCTION:    getDefaultPlist
0134 %
0135 % DESCRIPTION: Get Default Plist
0136 %
0137 % HISTORY:     11-07-07 M Hewitson
0138 %                Creation.
0139 %
0140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0141 
0142 function plo = getDefaultPlist()
0143   plo = plist('name', '');
0144 end
0145

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003