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