Skip to content

Commit aa2378b

Browse files
committed
[c++/m] Add Group getByIndex functions
Implements the getByIndex functions on the c++ and the Matlab side and adds corresponding tests. - getSource - getDataArray - getTag - getMultiTag
1 parent 4b6f942 commit aa2378b

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed

+nix/Group.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
'Group::getDataArray', id_or_name, @nix.DataArray);
4545
end;
4646

47+
function retObj = open_data_array_idx(obj, idx)
48+
retObj = nix.Utils.open_entity(obj, ...
49+
'Group::openDataArrayIdx', idx, @nix.DataArray);
50+
end
51+
4752
function [] = add_data_array(obj, add_this)
4853
nix.Utils.add_entity(obj, add_this, ...
4954
'nix.DataArray', 'Group::addDataArray');
@@ -82,6 +87,11 @@
8287
'Group::getTag', id_or_name, @nix.Tag);
8388
end;
8489

90+
function retObj = open_tag_idx(obj, idx)
91+
retObj = nix.Utils.open_entity(obj, ...
92+
'Group::openTagIdx', idx, @nix.Tag);
93+
end
94+
8595
function delCheck = remove_tag(obj, del)
8696
delCheck = nix.Utils.delete_entity(obj, del, ...
8797
'nix.Tag', 'Group::removeTag');
@@ -115,6 +125,11 @@
115125
'Group::getMultiTag', id_or_name, @nix.MultiTag);
116126
end;
117127

128+
function retObj = open_multi_tag_idx(obj, idx)
129+
retObj = nix.Utils.open_entity(obj, ...
130+
'Group::openMultiTagIdx', idx, @nix.MultiTag);
131+
end
132+
118133
function delCheck = remove_multi_tag(obj, del)
119134
delCheck = nix.Utils.delete_entity(obj, del, ...
120135
'nix.MultiTag', 'Group::removeMultiTag');

nix_mx.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ void mexFunction(int nlhs,
202202
methods->add("Group::addTags", nixgroup::addTags);
203203
methods->add("Group::addMultiTag", nixgroup::addMultiTag);
204204
methods->add("Group::addMultiTags", nixgroup::addMultiTags);
205+
methods->add("Group::openDataArrayIdx", nixgroup::openDataArrayIdx);
206+
methods->add("Group::openTagIdx", nixgroup::openTagIdx);
207+
methods->add("Group::openMultiTagIdx", nixgroup::openMultiTagIdx);
208+
methods->add("Group::openSourceIdx", nixgroup::openSourceIdx);
205209

206210
classdef<nix::DataArray>("DataArray", methods)
207211
.desc(&nixdataarray::describe)

src/nixgroup.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,28 @@ namespace nixgroup {
7373
currObj.multiTags(curr);
7474
}
7575

76+
void openDataArrayIdx(const extractor &input, infusor &output) {
77+
nix::Group currObj = input.entity<nix::Group>(1);
78+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
79+
output.set(0, currObj.getDataArray(idx));
80+
}
81+
82+
void openTagIdx(const extractor &input, infusor &output) {
83+
nix::Group currObj = input.entity<nix::Group>(1);
84+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
85+
output.set(0, currObj.getTag(idx));
86+
}
87+
88+
void openMultiTagIdx(const extractor &input, infusor &output) {
89+
nix::Group currObj = input.entity<nix::Group>(1);
90+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
91+
output.set(0, currObj.getMultiTag(idx));
92+
}
93+
94+
void openSourceIdx(const extractor &input, infusor &output) {
95+
nix::Group currObj = input.entity<nix::Group>(1);
96+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
97+
output.set(0, currObj.getSource(idx));
98+
}
99+
76100
} // namespace nixgroup

src/nixgroup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ namespace nixgroup {
3131

3232
void addMultiTags(const extractor &input, infusor &output);
3333

34+
void openDataArrayIdx(const extractor &input, infusor &output);
35+
36+
void openTagIdx(const extractor &input, infusor &output);
37+
38+
void openMultiTagIdx(const extractor &input, infusor &output);
39+
40+
void openSourceIdx(const extractor &input, infusor &output);
41+
3442
} // namespace nixgroup
3543

3644
#endif

tests/TestGroup.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
funcs{end+1} = @test_source_count;
3838
funcs{end+1} = @test_set_metadata;
3939
funcs{end+1} = @test_open_metadata;
40+
funcs{end+1} = @test_open_data_array_idx;
41+
funcs{end+1} = @test_open_tag_idx;
42+
funcs{end+1} = @test_open_multi_tag_idx;
43+
funcs{end+1} = @test_open_source_idx;
4044
end
4145

4246
%% Test: Access nix.Group attributes
@@ -780,3 +784,72 @@
780784

781785
assert(strcmp(g.open_metadata.name, 'testSection'));
782786
end
787+
788+
function [] = test_open_data_array_idx( varargin )
789+
%% Test Open DataArray by index
790+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
791+
b = f.create_block('testBlock', 'nixBlock');
792+
g = b.create_group('testGroup', 'nixGroup');
793+
d1 = b.create_data_array('testDataArray1', 'nixDataArray', nix.DataType.Double, [3 2]);
794+
d2 = b.create_data_array('testDataArray2', 'nixDataArray', nix.DataType.Double, [6 2]);
795+
d3 = b.create_data_array('testDataArray3', 'nixDataArray', nix.DataType.Double, [9 2]);
796+
g.add_data_array(d1);
797+
g.add_data_array(d2);
798+
g.add_data_array(d3);
799+
800+
assert(strcmp(f.blocks{1}.groups{1}.open_data_array_idx(0).name, d1.name));
801+
assert(strcmp(f.blocks{1}.groups{1}.open_data_array_idx(1).name, d2.name));
802+
assert(strcmp(f.blocks{1}.groups{1}.open_data_array_idx(2).name, d3.name));
803+
end
804+
805+
function [] = test_open_tag_idx( varargin )
806+
%% Test Open Tag by index
807+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
808+
b = f.create_block('testBlock', 'nixBlock');
809+
g = b.create_group('testGroup', 'nixGroup');
810+
t1 = b.create_tag('testTag1', 'nixTag', [1 2]);
811+
t2 = b.create_tag('testTag2', 'nixTag', [1 2]);
812+
t3 = b.create_tag('testTag3', 'nixTag', [1 2]);
813+
g.add_tag(t1);
814+
g.add_tag(t2);
815+
g.add_tag(t3);
816+
817+
assert(strcmp(f.blocks{1}.groups{1}.open_tag_idx(0).name, t1.name));
818+
assert(strcmp(f.blocks{1}.groups{1}.open_tag_idx(1).name, t2.name));
819+
assert(strcmp(f.blocks{1}.groups{1}.open_tag_idx(2).name, t3.name));
820+
end
821+
822+
function [] = test_open_multi_tag_idx( varargin )
823+
%% Test Open MultiTag by index
824+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
825+
b = f.create_block('testBlock', 'nixBlock');
826+
g = b.create_group('testGroup', 'nixGroup');
827+
d = b.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Bool, [2 3]);
828+
t1 = b.create_multi_tag('testMultiTag1', 'nixMultiTag', d);
829+
t2 = b.create_multi_tag('testMultiTag2', 'nixMultiTag', d);
830+
t3 = b.create_multi_tag('testMultiTag3', 'nixMultiTag', d);
831+
g.add_multi_tag(t1);
832+
g.add_multi_tag(t2);
833+
g.add_multi_tag(t3);
834+
835+
assert(strcmp(f.blocks{1}.groups{1}.open_multi_tag_idx(0).name, t1.name));
836+
assert(strcmp(f.blocks{1}.groups{1}.open_multi_tag_idx(1).name, t2.name));
837+
assert(strcmp(f.blocks{1}.groups{1}.open_multi_tag_idx(2).name, t3.name));
838+
end
839+
840+
function [] = test_open_source_idx( varargin )
841+
%% Test Open Source by index
842+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
843+
b = f.create_block('testBlock', 'nixBlock');
844+
g = b.create_group('testGroup', 'nixGroup');
845+
s1 = b.create_source('testSource1', 'nixSource');
846+
s2 = b.create_source('testSource2', 'nixSource');
847+
s3 = b.create_source('testSource3', 'nixSource');
848+
g.add_source(s1);
849+
g.add_source(s2);
850+
g.add_source(s3);
851+
852+
assert(strcmp(f.blocks{1}.groups{1}.open_source_idx(0).name, s1.name));
853+
assert(strcmp(f.blocks{1}.groups{1}.open_source_idx(1).name, s2.name));
854+
assert(strcmp(f.blocks{1}.groups{1}.open_source_idx(2).name, s3.name));
855+
end

0 commit comments

Comments
 (0)