comparison m-toolbox/classes/@collection/collection.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children a71a40911c27
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % COLLECTION constructor for collection class.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: COLLECTION constructor for collection class.
5 %
6 % CONSTRUCTOR:
7 %
8 % fb = collection() - creates an empty collection object
9 % fb = collection(objs) - construct from an array of objects
10 % fb = collection(pl) - create a collection object from a parameter list
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('collection', 'collection')">Parameters Description</a>
13 %
14 % VERSION: $Id: collection.m,v 1.29 2011/04/08 08:56:22 hewitson Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 classdef collection < ltpda_uoh
19
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21 % Property definition %
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
24 %---------- Public (read/write) Properties ----------
25 properties
26 objs = {}; % objects in collection
27 end
28
29 %---------- Protected read-only Properties ----------
30 properties (SetAccess = protected)
31 end
32
33 %---------- Private Properties ----------
34 properties (GetAccess = protected, SetAccess = protected)
35 end
36
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 % Check property setting %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41 methods
42 function set.objs(obj, val)
43 if ~iscell(val)
44 error('### The value for the property ''objs'' must be a cell object');
45 end
46 obj.objs = reshape(val, 1, []);
47 end
48 end
49
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 % Constructor %
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54 methods
55 function obj = collection(varargin)
56
57 import utils.const.*
58 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
59
60 % Collect all collection objects
61 [colls, invars, rest] = utils.helper.collect_objects(varargin(:), 'collection');
62
63 if (isempty(rest) || ...
64 ((numel(rest) == 1) && ...
65 (isa(rest{1}, 'plist')) && ...
66 (nparams(rest{1}) == 0)) ) && ~isempty(colls)
67 % Do copy constructor and return
68 utils.helper.msg(msg.OPROC1, 'copy constructor');
69 obj = copy(colls, 1);
70 for kk=1:numel(obj)
71 obj(kk).addHistory(collection.getInfo('collection', 'None'), [], [], obj(kk).hist);
72 end
73 return
74 end
75
76 switch nargin
77 case 0
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%% no input %%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 utils.helper.msg(msg.OPROC1, 'empty constructor');
82 obj.addHistory(collection.getInfo('collection', 'None'), plist(), [], []);
83
84 case 1
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 %%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%%
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89 if ischar(varargin{1})
90 %%%%%%%%%% pzm = collection('foo.mat') %%%%%%%%%%
91 %%%%%%%%%% pzm = collection('foo.xml') %%%%%%%%%%
92 utils.helper.msg(msg.OPROC1, 'constructing from file %s', varargin{1});
93 obj = fromFile(obj, varargin{1});
94
95 elseif isstruct(varargin{1})
96 %%%%%%%%%% r = collection(struct) %%%%%%%%%%
97 utils.helper.msg(msg.OPROC1, 'constructing from struct');
98 obj = fromStruct(obj, varargin{1});
99
100 elseif isa(varargin{1}, 'ltpda_uoh')
101 %%%%%%%%%% f = collection(a1) %%%%%%%%%%
102 obj = obj.fromInput(plist('objs', varargin));
103
104 elseif isa(varargin{1}, 'plist')
105 %%%%%%%%%% r = collection(plist) %%%%%%%%%%
106 pl = varargin{1};
107
108 if numel(pl) > 1
109 % The input is a vector of PLISTS
110 obj = obj.fromInput(plist('objs', num2cell(reshape(pl, 1, []))));
111
112 else
113
114 if pl.isparam('filename')
115 utils.helper.msg(msg.PROC2, 'constructing from file %s', pl.find('filename'));
116 obj = obj.fromFile(pl);
117
118 elseif pl.isparam('hostname') || pl.isparam('conn')
119 utils.helper.msg(msg.PROC2, 'constructing from repository %s', pl.find('hostname'));
120 obj = obj.fromRepository(pl);
121
122 elseif pl.isparam('objs')
123 obj = obj.fromInput(pl);
124
125 elseif pl.isparam('plist')
126 obj = collection(pl.find('plist'));
127
128 elseif pl.isparam('built-in')
129 utils.helper.msg(msg.OPROC1, 'constructing from built-in model');
130 obj = fromModel(obj, pl);
131
132 else
133 if pl.shouldIgnore()
134 % The PLIST is not a configuration PLIST
135 obj = obj.fromInput(plist('objs', {pl}));
136 else
137 obj.setProperties(pl);
138 obj.addHistory(collection.getInfo('collection', 'None'), pl, [], []);
139 end
140 end
141
142 end
143
144 else
145 error('### Unknown single argument constructor.');
146 end
147
148 case 2
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 %%%%%%%%%%%%%%%%%%%%%%%%%%% two inputs %%%%%%%%%%%%%%%%%%%%%%%%%%
151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152
153 if isa(varargin{1}, 'ltpda_uo') && isa(varargin{2}, 'ltpda_uo')
154 %%%%%%%%%% f = collection(a1, a2) %%%%%%%%%%
155 inObjs = [num2cell(reshape(varargin{1}, 1, [])), num2cell(reshape(varargin{2}, 1, []))];
156 obj = obj.fromInput(plist('objs', inObjs));
157
158 elseif (isa(varargin{1}, 'database') || isa(varargin{1}, 'mpipeline.repository.RepositoryConnection')) && isnumeric(varargin{2})
159 %%%%%%%%%% f = collection(<database-object>, [IDs]) %%%%%%%%%%
160 utils.helper.msg(msg.OPROC1, 'retrieve from repository');
161 obj = obj.fromRepository(plist('conn', varargin{1}, 'id', varargin{2}));
162
163 elseif isa(varargin{1}, 'ltpda_uo') && isa(varargin{2}, 'plist') && isempty(varargin{2}.params)
164 %%%%%%%%%% f = collection(collection-object, <empty plist>) %%%%%%%%%%
165 obj = collection(varargin{1});
166
167 elseif isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ...
168 isa(varargin{2}, 'history')
169 %%%%%%%%%% obj = collection(DOM node, history-objects) %%%%%%%%%%
170 obj = fromDom(obj, varargin{1}, varargin{2});
171
172 elseif isa(varargin{1}, 'ltpda_uoh') && isa(varargin{2}, 'plist')
173 %%%%%%%%%%% collection(<ltpda_uoh>-object, plist-object) %%%%%%%%%%
174 % always recreate from plist
175
176 % If we are trying to load from file, and the file exists, do
177 % that. Otherwise, copy the input object.
178 if varargin{2}.isparam('filename')
179 if exist(fullfile('.', find(varargin{2}, 'filename')), 'file')==2
180 obj = collection(varargin{2});
181 else
182 obj = collection(varargin{1});
183 end
184 else
185 obj = collection(varargin{2});
186 end
187 else
188 error('### Unknown 2 argument constructor.');
189 end
190
191 otherwise
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 %%%%%%%%%%%%%%%%%%%%%%%%%%% any input %%%%%%%%%%%%%%%%%%%%%%%%%%%
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 obj = obj.fromInput(plist('objs', varargin));
196 end
197
198 end % End constructor
199
200 end
201
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 % Methods (static) %
204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 methods (Static)
206
207 function mdls = getBuiltInModels(varargin)
208 mdls = ltpda_uo.getBuiltInModels('collection');
209 end
210
211 function out = VEROUT()
212 out = '$Id: collection.m,v 1.29 2011/04/08 08:56:22 hewitson Exp $';
213 end
214
215 function ii = getInfo(varargin)
216 ii = utils.helper.generic_getInfo(varargin{:}, 'collection');
217 end
218
219 function out = SETS()
220 out = [SETS@ltpda_uoh, {'From Input'}];
221 end
222
223 function plout = getDefaultPlist(set)
224 persistent pl;
225 persistent lastset;
226 if exist('pl', 'var')==0 || isempty(pl) || ~strcmp(lastset, set)
227 pl = collection.buildplist(set);
228 lastset = set;
229 end
230 plout = pl;
231 end
232
233 function out = buildplist(set)
234
235 if ~utils.helper.ismember(lower(collection.SETS), lower(set))
236 error('### Unknown set [%s]', set);
237 end
238
239 out = plist();
240 out = collection.addGlobalKeys(out);
241 out = buildplist@ltpda_uoh(out, set);
242
243 switch lower(set)
244 case 'from input'
245 p = param({'objs', 'Objects of the collection.<br>Please use a cell array if the objects are not from the same type.'}, paramValue.EMPTY_DOUBLE);
246 out.append(p);
247 end
248 end % function out = getDefaultPlist(varargin)
249
250 function obj = initObjectWithSize(n,m)
251 obj = collection.newarray([n m]);
252 end
253
254 varargout = identifyInsideObjs(varargin)
255
256 end % End static methods
257
258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 % Methods (static, private) %
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261
262 methods (Static, Access=private)
263 end % End static, private methods
264
265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 % Methods (static, hidden) %
267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268
269 methods (Static = true, Hidden = true)
270 varargout = loadobj(varargin)
271 varargout = update_struct(varargin);
272 end
273
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 % Methods (public) %
276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 methods
278
279 varargout = char(varargin)
280 varargout = display(varargin)
281 varargout = copy(varargin)
282 varargout = setObjs(varargin)
283 varargout = setObjectAtIndex(varargin)
284 varargout = getObjectAtIndex(varargin)
285 varargout = removeObjectAtIndex(varargin)
286 varargout = getObjectsOfClass(varargin)
287 end
288
289 methods (Hidden = true)
290 varargout = attachToDom(varargin)
291 end
292
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 % Methods (protected) %
295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
296 methods (Access = protected)
297 varargout = fromRepository(varargin)
298 varargout = fromInput(varargin)
299 varargout = fromStruct(varargin)
300 varargout = fromDom(varargin)
301 end
302
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % Methods (private) %
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 methods (Access = private)
307 end
308
309 end % End classdef
310