Skip to content

Commit c326c16

Browse files
committed
[c++/m] Add Section getByIndex functions
Implements the getByIndex functions on the c++ and the Matlab side and adds corresponding tests. - getSection - getProperty
1 parent 706138f commit c326c16

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

+nix/Section.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
retObj = nix.Utils.open_entity(obj, ...
8989
'Section::openSection', id_or_name, @nix.Section);
9090
end;
91+
92+
function retObj = open_section_idx(obj, idx)
93+
retObj = nix.Utils.open_entity(obj, ...
94+
'Section::openSectionIdx', idx, @nix.Section);
95+
end;
9196

9297
function hs = has_section(obj, id_or_name)
9398
hs = nix_mx('Section::hasSection', obj.nix_handle, id_or_name);
@@ -134,6 +139,11 @@
134139
'Section::openProperty', id_or_name, @nix.Property);
135140
end;
136141

142+
function retObj = open_property_idx(obj, idx)
143+
retObj = nix.Utils.open_entity(obj, ...
144+
'Section::openPropertyIdx', idx, @nix.Property);
145+
end;
146+
137147
function props = get.allProperties(obj)
138148
props = nix_mx('Section::properties', obj.nix_handle);
139149
end;

nix_mx.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ void mexFunction(int nlhs,
385385
methods->add("Section::referringBlockTags", nixsection::referringBlockTags);
386386
methods->add("Section::referringBlockMultiTags", nixsection::referringBlockMultiTags);
387387
methods->add("Section::referringBlockDataArrays", nixsection::referringBlockDataArrays);
388+
methods->add("Section::openSectionIdx", nixsection::openSectionIdx);
389+
methods->add("Section::openPropertyIdx", nixsection::openPropertyIdx);
388390

389391
classdef<nix::Feature>("Feature", methods)
390392
.desc(&nixfeature::describe)

src/nixsection.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@ namespace nixsection {
105105
output.set(0, currSec.referringDataArrays(currBlock));
106106
}
107107

108+
void openSectionIdx(const extractor &input, infusor &output) {
109+
nix::Section currObj = input.entity<nix::Section>(1);
110+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
111+
output.set(0, currObj.getSection(idx));
112+
}
113+
114+
void openPropertyIdx(const extractor &input, infusor &output) {
115+
nix::Section currObj = input.entity<nix::Section>(1);
116+
nix::ndsize_t idx = (nix::ndsize_t)input.num<double>(2);
117+
output.set(0, currObj.getProperty(idx));
118+
}
119+
108120
} // namespace nixsection

src/nixsection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace nixsection {
2929

3030
void referringBlockDataArrays(const extractor &input, infusor &output);
3131

32+
void openSectionIdx(const extractor &input, infusor &output);
33+
34+
void openPropertyIdx(const extractor &input, infusor &output);
3235
} // namespace nixsection
3336

3437
#endif

tests/TestSection.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
funcs{end+1} = @test_delete_section;
1616
funcs{end+1} = @test_list_subsections;
1717
funcs{end+1} = @test_open_section;
18+
funcs{end+1} = @test_open_section_idx;
1819
funcs{end+1} = @test_parent;
1920
funcs{end+1} = @test_has_section;
2021
funcs{end+1} = @test_section_count;
@@ -24,6 +25,7 @@
2425
funcs{end+1} = @test_create_property_with_value;
2526
funcs{end+1} = @test_delete_property;
2627
funcs{end+1} = @test_open_property;
28+
funcs{end+1} = @test_open_property_idx;
2729
funcs{end+1} = @test_property_count;
2830
funcs{end+1} = @test_link;
2931
funcs{end+1} = @test_inherited_properties;
@@ -90,6 +92,19 @@
9092
assert(isempty(getSection));
9193
end
9294

95+
function [] = test_open_section_idx( varargin )
96+
%% Test Open Section by index
97+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
98+
s = f.create_section('testSection', 'nixSection');
99+
s1 = s.create_section('testSection1', 'nixSection');
100+
s2 = s.create_section('testSection2', 'nixSection');
101+
s3 = s.create_section('testSection3', 'nixSection');
102+
103+
assert(strcmp(f.sections{1}.open_section_idx(0).name, s1.name));
104+
assert(strcmp(f.sections{1}.open_section_idx(1).name, s2.name));
105+
assert(strcmp(f.sections{1}.open_section_idx(2).name, s3.name));
106+
end
107+
93108
function [] = test_parent( varargin )
94109
%% Test: get parent section
95110
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
@@ -278,6 +293,19 @@
278293
assert(~isempty(trial.open_property(trial.allProperties{1}.name)));
279294
end
280295

296+
function [] = test_open_property_idx( varargin )
297+
%% Test Open Propery by index
298+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
299+
s = f.create_section('testSection', 'nixSection');
300+
p1 = s.create_property('testProperty1', nix.DataType.Double);
301+
p2 = s.create_property('testProperty2', nix.DataType.Bool);
302+
p3 = s.create_property('testProperty3', nix.DataType.String);
303+
304+
assert(strcmp(f.sections{1}.open_property_idx(0).name, p1.name));
305+
assert(strcmp(f.sections{1}.open_property_idx(1).name, p2.name));
306+
assert(strcmp(f.sections{1}.open_property_idx(2).name, p3.name));
307+
end
308+
281309
%% Test: Property count
282310
function [] = test_property_count( varargin )
283311
testFile = fullfile(pwd, 'tests', 'testRW.h5');

0 commit comments

Comments
 (0)