Skip to content

Commit a4147f5

Browse files
committed
[c++/m] Add Source getSourceByIndex function
1 parent 7d0c840 commit a4147f5

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

+nix/Source.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
'Source::openSource', id_or_name, @nix.Source);
5050
end;
5151

52+
function retObj = open_source_idx(obj, idx)
53+
retObj = nix.Utils.open_entity(obj, ...
54+
'Source::openSourceIdx', idx, @nix.Source);
55+
end;
56+
5257
function retObj = parent_source(obj)
5358
retObj = nix.Utils.fetchObj('Source::parentSource', ...
5459
obj.nix_handle, @nix.Source);

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void mexFunction(int nlhs,
266266
.reg("referringDataArrays", GETTER(std::vector<nix::DataArray>, nix::Source, referringDataArrays))
267267
.reg("referringTags", GETTER(std::vector<nix::Tag>, nix::Source, referringTags))
268268
.reg("referringMultiTags", GETTER(std::vector<nix::MultiTag>, nix::Source, referringMultiTags));
269+
methods->add("Source::openSourceIdx", nixsource::openSourceIdx);
269270

270271
classdef<nix::Tag>("Tag", methods)
271272
.desc(&nixtag::describe)

src/nixsource.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@ namespace nixsource {
2727
return sb.array();
2828
}
2929

30+
void openSourceIdx(const extractor &input, infusor &output) {
31+
nix::Source currObj = input.entity<nix::Source>(1);
32+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
33+
output.set(0, currObj.getSource(idx));
34+
}
35+
3036
} // namespace nixsource

src/nixsource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace nixsource {
1515

1616
mxArray *describe(const nix::Source &source);
1717

18+
void openSourceIdx(const extractor &input, infusor &output);
19+
1820
} // namespace nixsource
1921

2022
#endif

tests/TestSource.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
funcs{end+1} = @test_fetch_sources;
1818
funcs{end+1} = @test_has_source;
1919
funcs{end+1} = @test_open_source;
20+
funcs{end+1} = @test_open_source_idx;
2021
funcs{end+1} = @test_source_count;
2122
funcs{end+1} = @test_parent_source;
2223
funcs{end+1} = @test_set_metadata;
@@ -68,6 +69,20 @@
6869
assert(isempty(getNonSource));
6970
end
7071

72+
function [] = test_open_source_idx( varargin )
73+
%% Test Open Source by index
74+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
75+
b = f.create_block('testBlock', 'nixBlock');
76+
s = b.create_source('testSource', 'nixSource');
77+
s1 = s.create_source('testSource1', 'nixSource');
78+
s2 = s.create_source('testSource2', 'nixSource');
79+
s3 = s.create_source('testSource3', 'nixSource');
80+
81+
assert(strcmp(f.blocks{1}.sources{1}.open_source_idx(0).name, s1.name));
82+
assert(strcmp(f.blocks{1}.sources{1}.open_source_idx(1).name, s2.name));
83+
assert(strcmp(f.blocks{1}.sources{1}.open_source_idx(2).name, s3.name));
84+
end
85+
7186
%% Test: Source count
7287
function [] = test_source_count( varargin )
7388
testFile = fullfile(pwd, 'tests', 'testRW.h5');

0 commit comments

Comments
 (0)