Skip to content

Commit 8c9dbfa

Browse files
committed
[c++/m] Add Section compare function
Closes #127
1 parent e4aba3a commit 8c9dbfa

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ void mexFunction(int nlhs,
394394
methods->add("Section::referringBlockDataArrays", nixsection::referringBlockDataArrays);
395395
methods->add("Section::openSectionIdx", nixsection::openSectionIdx);
396396
methods->add("Section::openPropertyIdx", nixsection::openPropertyIdx);
397+
methods->add("Section::compare", nixsection::compare);
397398

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

src/nixsection.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,10 @@ namespace nixsection {
117117
output.set(0, currObj.getProperty(idx));
118118
}
119119

120+
void compare(const extractor &input, infusor &output) {
121+
nix::Section currObj = input.entity<nix::Section>(1);
122+
nix::Section other = input.entity<nix::Section>(2);
123+
output.set(0, currObj.compare(other));
124+
}
125+
120126
} // namespace nixsection

src/nixsection.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ namespace nixsection {
3232
void openSectionIdx(const extractor &input, infusor &output);
3333

3434
void openPropertyIdx(const extractor &input, infusor &output);
35+
36+
void compare(const extractor &input, infusor &output);
37+
3538
} // namespace nixsection
3639

3740
#endif

tests/TestSection.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
funcs{end+1} = @test_referring_sources;
3939
funcs{end+1} = @test_referring_block_sources;
4040
funcs{end+1} = @test_referring_blocks;
41+
funcs{end+1} = @test_compare;
4142
end
4243

4344
%% Test: Create Section
@@ -608,3 +609,14 @@
608609
b2.set_metadata('')
609610
assert(size(s.referring_blocks, 1) == 1);
610611
end
612+
613+
function [] = test_compare( varargin )
614+
%% Test: Compare group entities
615+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
616+
s1 = f.create_section('testSection1', 'nixSection');
617+
s2 = f.create_section('testSection2', 'nixSection');
618+
619+
assert(s1.compare(s2) < 0);
620+
assert(s1.compare(s1) == 0);
621+
assert(s2.compare(s1) > 0);
622+
end

0 commit comments

Comments
 (0)