Skip to content

Commit 1029a24

Browse files
committed
[c++/m] Add Group compare function
1 parent 70bae91 commit 1029a24

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ void mexFunction(int nlhs,
207207
methods->add("Group::openTagIdx", nixgroup::openTagIdx);
208208
methods->add("Group::openMultiTagIdx", nixgroup::openMultiTagIdx);
209209
methods->add("Group::openSourceIdx", nixgroup::openSourceIdx);
210+
methods->add("Group::compare", nixgroup::compare);
210211

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

src/nixgroup.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,10 @@ namespace nixgroup {
9797
output.set(0, currObj.getSource(idx));
9898
}
9999

100+
void compare(const extractor &input, infusor &output) {
101+
nix::Group currObj = input.entity<nix::Group>(1);
102+
nix::Group other = input.entity<nix::Group>(2);
103+
output.set(0, currObj.compare(other));
104+
}
105+
100106
} // namespace nixgroup

src/nixgroup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace nixgroup {
3939

4040
void openSourceIdx(const extractor &input, infusor &output);
4141

42+
void compare(const extractor &input, infusor &output);
43+
4244
} // namespace nixgroup
4345

4446
#endif

tests/TestGroup.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
funcs{end+1} = @test_open_tag_idx;
4242
funcs{end+1} = @test_open_multi_tag_idx;
4343
funcs{end+1} = @test_open_source_idx;
44+
funcs{end+1} = @test_compare;
4445
end
4546

4647
%% Test: Access nix.Group attributes
@@ -853,3 +854,18 @@
853854
assert(strcmp(f.blocks{1}.groups{1}.open_source_idx(1).name, s2.name));
854855
assert(strcmp(f.blocks{1}.groups{1}.open_source_idx(2).name, s3.name));
855856
end
857+
858+
function [] = test_compare( varargin )
859+
%% Test: Compare group entities
860+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
861+
b1 = f.create_block('testBlock1', 'nixBlock');
862+
b2 = f.create_block('testBlock2', 'nixBlock');
863+
g1 = b1.create_group('testGroup1', 'nixGroup');
864+
g2 = b1.create_group('testGroup2', 'nixGroup');
865+
g3 = b2.create_group('testGroup1', 'nixGroup');
866+
867+
assert(g1.compare(g2) < 0);
868+
assert(g1.compare(g1) == 0);
869+
assert(g2.compare(g1) > 0);
870+
assert(g1.compare(g3) ~= 0);
871+
end

0 commit comments

Comments
 (0)