Skip to content

Commit e4aba3a

Browse files
committed
[c++/m] Add MultiTag compare function
1 parent 7bfd9ea commit e4aba3a

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ void mexFunction(int nlhs,
354354
methods->add("MultiTag::openReferenceIdx", nixmultitag::openReferenceIdx);
355355
methods->add("MultiTag::openFeatureIdx", nixmultitag::openFeatureIdx);
356356
methods->add("MultiTag::openSourceIdx", nixmultitag::openSourceIdx);
357+
methods->add("MultiTag::compare", nixmultitag::compare);
357358

358359
classdef<nix::Section>("Section", methods)
359360
.desc(&nixsection::describe)

src/nixmultitag.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ namespace nixmultitag {
101101
output.set(0, currObj.getSource(idx));
102102
}
103103

104+
void compare(const extractor &input, infusor &output) {
105+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
106+
nix::MultiTag other = input.entity<nix::MultiTag>(2);
107+
output.set(0, currObj.compare(other));
108+
}
109+
104110
} // namespace nixmultitag

src/nixmultitag.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace nixmultitag {
3737

3838
void openSourceIdx(const extractor &input, infusor &output);
3939

40+
void compare(const extractor &input, infusor &output);
41+
4042
} // namespace nixmultitag
4143

4244
#endif

tests/TestMultiTag.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
funcs{end+1} = @test_retrieve_feature_data;
4545
funcs{end+1} = @test_set_units;
4646
funcs{end+1} = @test_attrs;
47+
funcs{end+1} = @test_compare;
4748
end
4849

4950
%% Test: Add sources by entity and id
@@ -761,3 +762,20 @@
761762
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
762763
assert(isequal(f.blocks{1}.multiTags{1}.type, testType));
763764
end
765+
766+
function [] = test_compare( varargin )
767+
%% Test: Compare MultiTag entities
768+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
769+
b1 = f.create_block('testBlock1', 'nixBlock');
770+
b2 = f.create_block('testBlock2', 'nixBlock');
771+
d = b1.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Double, [2 2]);
772+
t1 = b1.create_multi_tag('testMultiTag1', 'nixMultiTag', d);
773+
t2 = b1.create_multi_tag('testMultiTag2', 'nixMultiTag', d);
774+
d = b2.create_data_array('testDataArray', 'nixDataArray', nix.DataType.Double, [2 2]);
775+
t3 = b2.create_multi_tag('testMultiTag1', 'nixMultiTag', d);
776+
777+
assert(t1.compare(t2) < 0);
778+
assert(t1.compare(t1) == 0);
779+
assert(t2.compare(t1) > 0);
780+
assert(t1.compare(t3) ~= 0);
781+
end

0 commit comments

Comments
 (0)