comparison m-toolbox/classes/@ssmport/ssmport.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 % SSMPORT a helper class for the SSM class.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % SSMPORT a helper class for the SSM class.
5 %
6 % SUPERCLASSES: ltpda_nuo < ltpda_obj
7 %
8 % CONSTRUCTORS:
9 %
10 % sb = ssmport(name);
11 % sb = ssmport(name, desc);
12 % sb = ssmport(name, desc, units);
13 %
14 % VERSION: $Id: ssmport.m,v 1.22 2011/03/28 17:02:29 ingo Exp $
15 %
16 % SEE ALSO: ltpda_obj, ltpda_nuo, ssm
17 %
18 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
20 classdef (Hidden = true) ssmport < ltpda_nuo
21
22 %% -------- Public (read/write) Properties -------
23 properties
24 end % -------- Public (read/write) Properties -------
25
26 %% -------- Private read-only Properties --------
27 properties (SetAccess = protected)
28 name = '.'; % name of the block
29 units = unit(); % units associated with this port
30 description = ''; % description of the block
31 end %% -------- Private read-only Properties --------
32
33 %% -------- Dependant Hidden Properties ---------
34 properties (Dependent, Hidden)
35 end %-------- Dependant Hidden Properties ---------
36
37 %% -------- Dependant Hidden Properties Methods ------
38 methods
39
40 end % -------- Dependant Properties Methods ------
41
42 %% -------- constructor ------
43 methods
44
45 function sp = ssmport(varargin)
46 switch nargin
47 case 0
48 % Empty constructor
49 case 1
50 if isa(varargin{1}, 'ssmport')
51 % copy constructor.
52 sp = copy(varargin{1},1);
53 elseif isstruct(varargin{1})
54 % sp = ssmport(struct)
55 sp = fromStruct(sp, varargin{1});
56 else
57 error('### Unknown single argument constructor: ssmport(%s)', class(varargin{1}));
58 end
59 case 2
60 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ...
61 isa(varargin{2}, 'history')
62 sp = fromDom(sp, varargin{1}, varargin{2});
63 else
64 error('### Unknown two argument constructor: ssmport(%s, %s)', class(varargin{1}), class(varargin{2}));
65 end
66 otherwise
67 error('### Unknown argument constructor');
68 end
69 end % End constructor
70
71 end %% -------- constructor ------
72
73 %% -------- Hidden methods ------
74 methods (Hidden = true)
75
76 varargout = attachToDom(varargin)
77
78 function clearAllUnits(inputs)
79 for kk=1:numel(inputs)
80 inputs(kk).units = [];
81 end
82 end
83
84 %% properties methods
85 function portNames = portNames(port)
86 portNames = cell(1, numel(port));
87 for i=1:numel(port)
88 portNames{i} = port(i).name;
89 end
90 end
91
92 function portDescriptions = portDescriptions(port)
93 portDescriptions = cell(1, numel(port));
94 for i=1:numel(port)
95 portDescriptions{i} = port(i).description;
96 end
97 end
98
99 function portUnits = portUnits(port)
100 portUnits = unit.initObjectWithSize(1, numel(port));
101 for i=1:numel(port)
102 portUnits(i) = port(i).units;
103 end
104 end
105
106 %% No search methods in this class
107
108 %% set methods
109 function port = setName(port, names, blockName)
110 % checking block name is acceptable
111 blockName = upper(blockName);
112 if numel(strfind(blockName,'.'))>0
113 error('The "." is not allowed in ssmblock name')
114 end
115 if numel(strfind(blockName,' '))>0
116 error('The space " " is not allowed in ssmblock name')
117 end
118 % setting portNames depending on wether they are provided or not
119 if isempty(names) % setting for empty port names
120 for ii=1:numel(port)
121 port(ii).name = [blockName '.variable_' num2str(ii)];
122 end
123 else % setting for char/cellstr port names
124 if ischar(names), names = {names}; end
125 for ii=1:numel(port)
126 portName = names{ii};
127 if numel(strfind(portName,'.'))>0
128 error('The "." is not allowed in ssmport name')
129 end
130 if numel(strfind(portName,' '))>0
131 error('The space " " is not allowed in ssmport name')
132 end
133 port(ii).name = [blockName '.' lower(portName)];
134 end
135 end
136 end
137
138 function port = modifyBlockName(port, oldName, newName)
139 if numel(strfind(newName,'.'))>0
140 error('The "." is not allowed in ssmblock name')
141 end
142 if numel(strfind(newName,' '))>0
143 error('The space " " is not allowed in ssmblock name')
144 end
145 newName = upper(newName);
146 for ii=1:numel(port)
147 if ~isempty(port(ii).name)
148 str = port(ii).name;
149 [blockName, portName] = ssmblock.splitName(str);
150 port(ii).name = [newName '.' portName];
151 end
152 end
153 end
154
155 function port = setDescription(port, descriptions)
156 if ischar(descriptions), descriptions = {descriptions}; end
157 if numel(descriptions)==1
158 for ii=1:numel(port)
159 port(ii).description = descriptions{1};
160 end
161 else
162 for ii=1:numel(port)
163 port(ii).description = descriptions{ii};
164 end
165 end
166 end
167
168 function port = setUnits(port, units)
169 if ~isa(units, 'unit')
170 error('the port unit field must be of class unit')
171 end
172 if numel(units)==1
173 for ii=1:numel(port)
174 port(ii).units = units(1);
175 end
176 else
177 for ii=1:numel(port)
178 port(ii).units = units(ii);
179 end
180 end
181 end
182
183 end %% -------- Hidden methods ------
184
185 %% -------- private static methods ------
186 methods (Static=true, Access=private)
187 end %% -------- private static methods ------
188
189 %% -------- public static methods ------
190 methods (Static=true)
191
192 function obj = initObjectWithSize(n,m)
193 obj = ssmport.newarray([n m]);
194 end
195
196 function out = VEROUT()
197 out = '$Id: ssmport.m,v 1.22 2011/03/28 17:02:29 ingo Exp $';
198 end
199
200 function ii = getInfo(varargin)
201 ii = utils.helper.generic_getInfo(varargin{:}, 'ssmport');
202 end
203
204 function out = SETS()
205 out = {'Default'};
206 end
207
208 function out = getDefaultPlist(set)
209 switch lower(set)
210 case 'default'
211 out = plist();
212 otherwise
213 error('### Unknown set [%s]', set);
214 end
215 end
216
217 end %% -------- public static methods ------
218
219 %% ---------- public static hidden methods ---------------
220 methods (Static = true, Hidden = true)
221 varargout = loadobj(varargin)
222 varargout = update_struct(varargin);
223 end
224
225 %% -------- Declaration of Private methods --------
226 methods(Access = private)
227 end
228
229 methods (Access = protected)
230 varargout = fromStruct(varargin)
231 varargout = fromDom(varargin)
232 end
233
234 end