Mercurial > hg > ltpda
comparison m-toolbox/classes/@collection/setObjectAtIndex.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 % SETOBJECTATINDEX sets an input object to the collection. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: SETOBJECTATINDEX sets an input object to the collection. | |
5 % | |
6 % CALL: coll = setObjectAtIndex(coll, ao(), 1) | |
7 % coll = coll.setObjectAtIndex(plist('object', ao(), 'index', 1)); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('collection', 'setObjectAtIndex')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: setObjectAtIndex.m,v 1.9 2011/04/08 08:56:22 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = setObjectAtIndex(varargin) | |
16 | |
17 %%% Check if this is a call for parameters | |
18 if utils.helper.isinfocall(varargin{:}) | |
19 varargout{1} = getInfo(varargin{3}); | |
20 return | |
21 end | |
22 | |
23 %%% Internal call: Only one object + don't look for a plist | |
24 if utils.helper.callerIsMethod | |
25 %%% decide whether we modify the first object, or create a new one. | |
26 varargin{1} = copy(varargin{1}, nargout); | |
27 for ii = 1:numel(varargin{1}) | |
28 varargin{1}(ii).objs{varargin{3}} = varargin{2}; | |
29 end | |
30 varargout{1} = varargin{1}; | |
31 return | |
32 end | |
33 | |
34 import utils.const.* | |
35 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
36 | |
37 % Collect input variable names | |
38 in_names = cell(size(varargin)); | |
39 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
40 | |
41 % Collect objects | |
42 [colls, colls_invars, rest] = utils.helper.collect_objects(varargin(:), 'collection', in_names); | |
43 [pls, dummy, rest] = utils.helper.collect_objects(rest(:), 'plist'); | |
44 [idxs, dummy, objs] = utils.helper.collect_objects(rest(:), 'double'); | |
45 | |
46 %%% If pls contains only one plist with the single key 'object' and | |
47 %%% 'index' then set the property with a plist. | |
48 if length(pls) == 1 && isa(pls, 'plist') && nparams(pls) == 2 && pls.isparam('object') && pls.isparam('index') | |
49 objs = {}; | |
50 o = pls.find('object'); | |
51 if ~iscell(o) | |
52 o = num2cell(o); | |
53 end | |
54 for ll = 1:numel(o) | |
55 objs = [objs o(ll)]; | |
56 end | |
57 idxs = pls.find('index'); | |
58 else | |
59 objs = [objs num2cell(reshape(pls, 1, []))]; | |
60 end | |
61 | |
62 if numel(idxs) ~= numel(objs) | |
63 error('### Please specify for each input object an index. Number of objects %d and number of indices %d', numel(objs), numel(idxs)) | |
64 end | |
65 | |
66 %%% Create plist for history | |
67 plh = combine(pls, plist('object', objs, 'index', idxs)); | |
68 | |
69 % Decide on a deep copy or a modify | |
70 colls = copy(colls, nargout); | |
71 | |
72 % Loop over objects | |
73 for oo=1:numel(colls) | |
74 for ii=1:numel(idxs) | |
75 colls(oo).objs{idxs(ii)} = objs{ii}; | |
76 end | |
77 colls(oo).addHistory(getInfo('None'), plh, colls_invars(oo), colls(oo).hist); | |
78 end | |
79 | |
80 % Set output | |
81 if nargout == numel(colls) | |
82 % List of outputs | |
83 for ii = 1:numel(colls) | |
84 varargout{ii} = colls(ii); | |
85 end | |
86 else | |
87 % Single output | |
88 varargout{1} = colls; | |
89 end | |
90 end | |
91 | |
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
93 % Local Functions % | |
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
95 %-------------------------------------------------------------------------- | |
96 % Get Info Object | |
97 %-------------------------------------------------------------------------- | |
98 function ii = getInfo(varargin) | |
99 | |
100 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
101 sets = {}; | |
102 pl = []; | |
103 else | |
104 sets = {'Default'}; | |
105 pl = getDefaultPlist; | |
106 end | |
107 % Build info object | |
108 ii = minfo(mfilename, 'collection', 'ltpda', utils.const.categories.helper, '$Id: setObjectAtIndex.m,v 1.9 2011/04/08 08:56:22 hewitson Exp $', sets, pl); | |
109 end | |
110 | |
111 %-------------------------------------------------------------------------- | |
112 % Get Default Plist | |
113 %-------------------------------------------------------------------------- | |
114 function plout = getDefaultPlist() | |
115 persistent pl; | |
116 if exist('pl', 'var')==0 || isempty(pl) | |
117 pl = buildplist(); | |
118 end | |
119 plout = pl; | |
120 end | |
121 | |
122 function plo = buildplist() | |
123 plo = plist(); | |
124 | |
125 p = param({'object', 'An ltpda_uoh object which is to be packed in the collection object.'}, paramValue.EMPTY_DOUBLE); | |
126 plo.append(p); | |
127 | |
128 p = param({'index', 'Position of the object in the collection.'}, paramValue.EMPTY_DOUBLE); | |
129 plo.append(p); | |
130 | |
131 end | |
132 |