Skip to content

Commit 70bae91

Browse files
committed
[c++/m] Add Block compare function
Add compare function to the c++ side and a corresponding test on the matlab side.
1 parent 2f89bcb commit 70bae91

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ void mexFunction(int nlhs,
165165
methods->add("Block::openTagIdx", nixblock::openTagIdx);
166166
methods->add("Block::openMultiTagIdx", nixblock::openMultiTagIdx);
167167
methods->add("Block::openSourceIdx", nixblock::openSourceIdx);
168+
methods->add("Block::compare", nixblock::compare);
168169

169170
classdef<nix::Group>("Group", methods)
170171
.desc(&nixgroup::describe)

src/nixblock.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,10 @@ namespace nixblock {
9090
output.set(0, currObj.getSource(idx));
9191
}
9292

93+
void compare(const extractor &input, infusor &output) {
94+
nix::Block currObj = input.entity<nix::Block>(1);
95+
nix::Block other = input.entity<nix::Block>(2);
96+
output.set(0, currObj.compare(other));
97+
}
98+
9399
} // namespace nixblock

src/nixblock.h

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

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

34+
void compare(const extractor &input, infusor &output);
35+
3436
} // namespace nixblock
3537

3638
#endif

tests/TestBlock.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
funcs{end+1} = @test_tag_count;
5050
funcs{end+1} = @test_multi_tag_count;
5151
funcs{end+1} = @test_source_count;
52+
funcs{end+1} = @test_compare;
5253
end
5354

5455
function [] = test_attrs( varargin )
@@ -741,3 +742,14 @@
741742
f = nix.File(testFile, nix.FileMode.ReadOnly);
742743
assert(f.blocks{1}.source_count() == 2);
743744
end
745+
746+
function [] = test_compare( varargin )
747+
%% Test: Compare block entities
748+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
749+
b1 = f.create_block('testBlock1', 'nixBlock');
750+
b2 = f.create_block('testBlock2', 'nixBlock');
751+
752+
assert(b1.compare(b2) < 0);
753+
assert(b1.compare(b1) == 0);
754+
assert(b2.compare(b1) > 0);
755+
end

0 commit comments

Comments
 (0)