comparison m-toolbox/classes/@collection/getObjectsOfClass.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 % GETOBJECTSOFCLASS returns all objects of the specified class in a collection-object.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: GETOBJECTSOFCLASS returns all objects of the specified class
5 % in a collection-object.
6 % This doesn't captures the history.
7 %
8 % CALL: b = getObjectsOfClass(coll, i)
9 % b = getObjectsOfClass(coll, i, j)
10 % b = coll.getObjectsOfClass(plist('class', 'ao'))
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('collection', 'getObjectsOfClass')">Parameters Description</a>
13 %
14 % VERSION: $Id: getObjectsOfClass.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 function varargout = getObjectsOfClass(varargin)
19
20 % Check if this is a call for parameters
21 if utils.helper.isinfocall(varargin{:})
22 varargout{1} = getInfo(varargin{3});
23 return
24 end
25
26 if nargout == 0
27 error('### getObjectsOfClass cannot be used as a modifier. Please give an output variable.');
28 end
29
30 import utils.const.*
31 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
32
33 % Collect input variable names
34 in_names = cell(size(varargin));
35 for ii = 1:nargin,in_names{ii} = inputname(ii);end
36
37 % Collect all 'ltpda_uoh' objects and plists
38 [colls, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'collection', in_names);
39 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
40
41 % Combine plists
42 pl = combine(pl, getDefaultPlist);
43
44 cl = pl.find('class');
45
46 if isempty(cl) && ~isempty(rest)
47 cl = rest{1};
48 pl.pset('class', cl);
49 end
50
51 if isempty(cl) || ~ischar(cl)
52 error('### Please specify the class as a string in a plist or direct.');
53 end
54
55 objs = [];
56
57 for oo = 1:numel(colls)
58 for ii = 1:numel(colls(oo).objs)
59 if isa(colls(oo).objs{ii}, cl)
60 objs = [objs colls(oo).objs{ii}];
61 end
62 end
63 end
64
65 % Set output
66 varargout{1} = objs;
67 end
68
69 %--------------------------------------------------------------------------
70 % Get Info Object
71 %--------------------------------------------------------------------------
72 function ii = getInfo(varargin)
73 if nargin == 1 && strcmpi(varargin{1}, 'None')
74 sets = {};
75 pl = [];
76 else
77 sets = {'Default'};
78 pl = getDefaultPlist;
79 end
80 % Build info object
81 ii = minfo(mfilename, 'collection', 'ltpda', utils.const.categories.helper, '$Id: getObjectsOfClass.m,v 1.7 2011/04/08 08:56:21 hewitson Exp $', sets, pl);
82 ii.setModifier(false);
83 end
84
85 %--------------------------------------------------------------------------
86 % Get Default Plist
87 %--------------------------------------------------------------------------
88 function plout = getDefaultPlist()
89 persistent pl;
90 if exist('pl', 'var')==0 || isempty(pl)
91 pl = buildplist();
92 end
93 plout = pl;
94 end
95
96 function plo = buildplist()
97 plo = plist();
98
99 p = param({'class', 'Class name which should be collected.'}, paramValue.EMPTY_STRING);
100 plo.append(p);
101 end
102