Skip to content

Commit 7bfd9ea

Browse files
committed
[c++/m] Add Tag compare function
1 parent 9f30f82 commit 7bfd9ea

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
@@ -311,6 +311,7 @@ void mexFunction(int nlhs,
311311
methods->add("Tag::openReferenceIdx", nixtag::openReferenceIdx);
312312
methods->add("Tag::openFeatureIdx", nixtag::openFeatureIdx);
313313
methods->add("Tag::openSourceIdx", nixtag::openSourceIdx);
314+
methods->add("Tag::compare", nixtag::compare);
314315

315316
classdef<nix::MultiTag>("MultiTag", methods)
316317
.desc(&nixmultitag::describe)

src/nixtag.cc

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

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

src/nixtag.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace nixtag {
3535

3636
void openSourceIdx(const extractor &input, infusor &output);
3737

38+
void compare(const extractor &input, infusor &output);
39+
3840
} // namespace nixtag
3941

4042
#endif

tests/TestTag.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
funcs{end+1} = @test_attrs;
4040
funcs{end+1} = @test_has_feature;
4141
funcs{end+1} = @test_has_reference;
42+
funcs{end+1} = @test_compare;
4243
end
4344

4445
%% Test: Add sources by entity and id
@@ -636,3 +637,18 @@
636637
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
637638
assert(f.blocks{1}.tags{1}.has_reference(daName));
638639
end
640+
641+
function [] = test_compare( varargin )
642+
%% Test: Compare Tag entities
643+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
644+
b1 = f.create_block('testBlock1', 'nixBlock');
645+
b2 = f.create_block('testBlock2', 'nixBlock');
646+
t1 = b1.create_tag('testTag1', 'nixTag', [1 2 3]);
647+
t2 = b1.create_tag('testTag2', 'nixTag', [1 2 3]);
648+
t3 = b2.create_tag('testTag1', 'nixTag', [1 2 3]);
649+
650+
assert(t1.compare(t2) < 0);
651+
assert(t1.compare(t1) == 0);
652+
assert(t2.compare(t1) > 0);
653+
assert(t1.compare(t3) ~= 0);
654+
end

0 commit comments

Comments
 (0)