Mercurial > hg > ltpda
comparison m-toolbox/classes/@ltpda_uo/setName.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % SETNAME Sets the property 'name' of an ltpda_uoh object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Sets the property 'name' of an ltpda_uoh object. | |
5 % | |
6 % CALL: objs.setName(val); | |
7 % objs.setName(val1, val2); | |
8 % objs.setName(plist('name', val)); | |
9 % objs = setName(); | |
10 % | |
11 % EXAMPLE: objs.setName() -> Sets the name to the variable name. | |
12 % In this case to 'objs' | |
13 % | |
14 % INPUTS: objs: Can be a vector, matrix, list, or a mix of them. | |
15 % val: | |
16 % 1. Single string e.g. 'val' | |
17 % Each object in objs get this value. | |
18 % 2. Single string in a cell-array e.g. {'val'} | |
19 % Each object in objs get this value. | |
20 % 3. cell-array with the same number of strings as in objs | |
21 % e.g. {'val1', 'val2', 'val3'} and 3 objects in objs | |
22 % Each object in objs get its corresponding value from the | |
23 % cell-array | |
24 % | |
25 % <a href="matlab:utils.helper.displayMethodInfo('ltpda_uoh', 'setName')">Parameters Description</a> | |
26 % | |
27 % VERSION: $Id: setName.m,v 1.20 2011/09/16 05:00:38 hewitson Exp $ | |
28 % | |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
30 | |
31 function varargout = setName(varargin) | |
32 | |
33 % Check if this is a call from a class method | |
34 callerIsMethod = utils.helper.callerIsMethod; | |
35 | |
36 if callerIsMethod | |
37 in_names = {}; | |
38 else | |
39 % Collect input variable names | |
40 in_names = cell(size(varargin)); | |
41 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
42 end | |
43 | |
44 objects = setPropertyValue(... | |
45 varargin{:}, ... | |
46 in_names, ... | |
47 callerIsMethod, ... | |
48 'name', ... | |
49 @setterFcn, ... | |
50 nargout, ... | |
51 @getInfo); | |
52 | |
53 % set outputs | |
54 varargout = utils.helper.setoutputs(nargout, objects); | |
55 | |
56 % Setter function to set the name | |
57 function value = setterFcn(varargin) | |
58 | |
59 obj = varargin{1}; | |
60 pl = varargin{2}; | |
61 if nargin > 2 | |
62 value = varargin{3}; | |
63 else | |
64 value = in_names{1}; | |
65 % Here we need to create the plist that will end up in the history | |
66 % because we want this actually variable name to be in the history | |
67 % otherwise the rebuild would end up setting the generated variable | |
68 % name as the object name. | |
69 pl.pset('name', value); | |
70 end | |
71 | |
72 MAX_LENGTH = 200; | |
73 | |
74 if ~ischar(value) | |
75 error('The ''name'' property requires a string value'); | |
76 end | |
77 | |
78 if length(value) > MAX_LENGTH | |
79 chop = floor(MAX_LENGTH/2); | |
80 value = [value(1:chop) ' ... ' value(end-chop:end)]; | |
81 end | |
82 | |
83 obj.name = value; | |
84 | |
85 end | |
86 | |
87 end | |
88 | |
89 | |
90 | |
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
92 % Local Functions % | |
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
94 | |
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
96 % | |
97 % FUNCTION: getInfo | |
98 % | |
99 % DESCRIPTION: Get Info Object | |
100 % | |
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
102 | |
103 function ii = getInfo(varargin) | |
104 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
105 sets = {}; | |
106 pl = []; | |
107 else | |
108 sets = {'Default'}; | |
109 pl = getDefaultPlist; | |
110 end | |
111 % Build info object | |
112 ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setName.m,v 1.20 2011/09/16 05:00:38 hewitson Exp $', sets, pl); | |
113 end | |
114 | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 % | |
117 % FUNCTION: getDefaultPlist | |
118 % | |
119 % DESCRIPTION: Get Default Plist | |
120 % | |
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
122 | |
123 function plout = getDefaultPlist() | |
124 persistent pl; | |
125 if ~exist('pl', 'var') || isempty(pl) | |
126 pl = buildplist(); | |
127 end | |
128 plout = pl; | |
129 end | |
130 | |
131 function pl = buildplist() | |
132 pl = plist({'name', 'New name for the object.'}, ''); | |
133 end | |
134 |