Skip to content

Commit 56ce652

Browse files
committed
[matlab] Add and use generic findXXX function
1 parent 247b31d commit 56ce652

File tree

5 files changed

+33
-61
lines changed

5 files changed

+33
-61
lines changed

+nix/Block.m

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,8 @@
191191

192192
% maxdepth is an index
193193
function sec = find_filtered_sources(obj, max_depth, filter, val)
194-
if (~isnumeric(max_depth))
195-
error('Provide a valid search depth');
196-
end
197-
198-
valid = nix.Utils.valid_filter(filter, val);
199-
if(~isempty(valid))
200-
error(valid);
201-
end
202-
203-
ret = nix_mx('Block::findSources', obj.nix_handle, ...
204-
max_depth, uint8(filter), val);
205-
sec = cell(length(ret), 1);
206-
for i = 1:length(ret)
207-
sec{i} = nix.Source(ret{i});
208-
end;
194+
sec = nix.Utils.find(obj, ...
195+
max_depth, filter, val, 'Block::findSources', @nix.Source);
209196
end
210197

211198
% -----------------
@@ -289,6 +276,6 @@
289276
filtered = nix.Utils.filter(obj, filter, val, ...
290277
'Block::multiTagsFiltered', @nix.MultiTag);
291278
end
279+
end
292280

293-
end;
294281
end

+nix/File.m

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,8 @@
120120

121121
% maxdepth is an index
122122
function sec = find_filtered_sections(obj, max_depth, filter, val)
123-
if (~isnumeric(max_depth))
124-
error('Provide a valid search depth');
125-
end
126-
127-
valid = nix.Utils.valid_filter(filter, val);
128-
if(~isempty(valid))
129-
error(valid);
130-
end
131-
132-
ret = nix_mx('File::findSections', obj.nix_handle, ...
133-
max_depth, uint8(filter), val);
134-
sec = cell(length(ret), 1);
135-
for i = 1:length(ret)
136-
sec{i} = nix.Section(ret{i});
137-
end;
123+
sec = nix.Utils.find(obj, ...
124+
max_depth, filter, val, 'File::findSections', @nix.Section);
138125
end
139126
end
140127

+nix/Section.m

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,8 @@
123123

124124
% maxdepth is an index
125125
function sec = find_filtered_sections(obj, max_depth, filter, val)
126-
if (~isnumeric(max_depth))
127-
error('Provide a valid search depth');
128-
end
129-
130-
valid = nix.Utils.valid_filter(filter, val);
131-
if(~isempty(valid))
132-
error(valid);
133-
end
134-
135-
ret = nix_mx('Section::findSections', obj.nix_handle, ...
136-
max_depth, uint8(filter), val);
137-
sec = cell(length(ret), 1);
138-
for i = 1:length(ret)
139-
sec{i} = nix.Section(ret{i});
140-
end;
126+
sec = nix.Utils.find(obj, ...
127+
max_depth, filter, val, 'Section::findSections', @nix.Section);
141128
end
142129

143130
% ----------------

+nix/Source.m

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,8 @@
8888
% maxdepth is an index where idx = 0 corresponds to the calling
8989
% source
9090
function sec = find_filtered_sources(obj, max_depth, filter, val)
91-
if (~isnumeric(max_depth))
92-
error('Provide a valid search depth');
93-
end
94-
95-
valid = nix.Utils.valid_filter(filter, val);
96-
if(~isempty(valid))
97-
error(valid);
98-
end
99-
100-
ret = nix_mx('Source::findSources', obj.nix_handle, ...
101-
max_depth, uint8(filter), val);
102-
sec = cell(length(ret), 1);
103-
for i = 1:length(ret)
104-
sec{i} = nix.Source(ret{i});
105-
end;
91+
sec = nix.Utils.find(obj, ...
92+
max_depth, filter, val, 'Source::findSources', @nix.Source);
10693
end
10794
end;
10895
end

+nix/Utils.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,29 @@
114114
end;
115115
end
116116

117+
% -----------------------------------------------------------
118+
% findXXX helper functions
119+
% -----------------------------------------------------------
120+
121+
function currData = find(obj, max_depth, filter, val, ...
122+
mxMethod, objConstructor)
123+
if (~isnumeric(max_depth))
124+
error('Provide a valid search depth');
125+
end
126+
127+
valid = nix.Utils.valid_filter(filter, val);
128+
if(~isempty(valid))
129+
error(valid);
130+
end
131+
132+
currList = nix_mx(mxMethod, ...
133+
obj.nix_handle, max_depth, uint8(filter), val);
134+
135+
currData = cell(length(currList), 1);
136+
for i = 1:length(currList)
137+
currData{i} = objConstructor(currList{i});
138+
end;
139+
end
140+
117141
end;
118142
end

0 commit comments

Comments
 (0)