comparison m-toolbox/classes/@collection/getObjectAtIndex.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 % GETOBJECTATINDEX index into the inner objects of one collection object.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: GETOBJECTATINDEX index into the inner objects of one
5 % collection object.
6 % This doesn't captures the history.
7 %
8 % CALL: b = getObjectAtIndex(coll, i)
9 % b = getObjectAtIndex(coll, i, j)
10 % b = coll.getObjectAtIndex(plist('I', i))
11 % b = coll.getObjectAtIndex(plist('I', i, 'J', j))
12 %
13 % <a href="matlab:utils.helper.displayMethodInfo('collection', 'getObjectAtIndex')">Parameters Description</a>
14 %
15 % VERSION: $Id: getObjectAtIndex.m,v 1.8 2011/04/08 08:56:21 hewitson Exp $
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 function varargout = getObjectAtIndex(varargin)
20
21 % Check if this is a call for parameters
22 if utils.helper.isinfocall(varargin{:})
23 varargout{1} = getInfo(varargin{3});
24 return
25 end
26
27 if nargout == 0
28 error('### getObjectAtIndex cannot be used as a modifier. Please give an output variable.');
29 end
30
31 import utils.const.*
32 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
33
34 % Collect input variable names
35 in_names = cell(size(varargin));
36 for ii = 1:nargin,in_names{ii} = inputname(ii);end
37
38 % Collect all 'ltpda_uoh' objects and plists
39 [cobjs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'collection', in_names);
40 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names);
41
42 % Combine plists
43 pl = combine(pl, getDefaultPlist);
44
45 % Get indices
46 idxi = find(pl, 'i');
47 idxj = find(pl, 'j');
48 if isempty(idxi) || isempty(idxj)
49 % go through the other inputs
50 for jj = 1:numel(rest)
51 if isnumeric(rest{jj}) && isempty(idxi)
52 idxi = rest{jj};
53 elseif isnumeric(rest{jj}) && isempty(idxj)
54 idxj = rest{jj};
55 end
56 end
57 end
58
59 if isempty(idxi) && isempty(idxj)
60 error('### Please provide an index or an index pair.');
61 end
62
63 % Now index with either (i) or (i,j)
64 if isempty(idxj)
65 if isa(cobjs.objs{idxi}, 'ltpda_obj')
66 aout = copy(cobjs.objs{idxi}, 1);
67 else
68 aout = cobjs.objs{idxi};
69 end
70 pl.pset('i', idxi);
71 else
72 if isa(cobjs.objs{idxi, idxj}, 'ltpda_obj')
73 aout = copy(cobjs.objs{idxi, idxj}, 1);
74 else
75 aout = cobjs.objs{idxi, idxj};
76 end
77 pl.pset('i', idxi);
78 pl.pset('j', idxj);
79 end
80
81 aout.addHistory(getInfo('None'), pl, obj_invars(1), cobjs.hist);
82
83 % Set output
84 varargout{1} = aout;
85 end
86
87 %--------------------------------------------------------------------------
88 % Get Info Object
89 %--------------------------------------------------------------------------
90 function ii = getInfo(varargin)
91 if nargin == 1 && strcmpi(varargin{1}, 'None')
92 sets = {};
93 pl = [];
94 else
95 sets = {'Default'};
96 pl = getDefaultPlist();
97 end
98 % Build info object
99 ii = minfo(mfilename, 'collection', 'ltpda', utils.const.categories.helper, '$Id: getObjectAtIndex.m,v 1.8 2011/04/08 08:56:21 hewitson Exp $', sets, pl);
100 ii.setModifier(false);
101 end
102
103 %--------------------------------------------------------------------------
104 % Get Default Plist
105 %--------------------------------------------------------------------------
106 function plout = getDefaultPlist()
107 persistent pl;
108 if ~exist('pl', 'var') || isempty(pl)
109 pl = buildplist();
110 end
111 plout = pl;
112 end
113
114 function plo = buildplist()
115
116 plo = plist();
117
118 p = param({'I', 'The I index of the inner object vector or matrix.'}, paramValue.EMPTY_DOUBLE);
119 plo.append(p);
120
121 p = param({'J', 'The J index of the inner object matrix.'}, paramValue.EMPTY_DOUBLE);
122 plo.append(p);
123
124 end
125