Skip to content

Commit 9f30f82

Browse files
committed
[c++/m] Add Source compare function
1 parent 80f47bd commit 9f30f82

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
@@ -271,6 +271,7 @@ void mexFunction(int nlhs,
271271
.reg("referringTags", GETTER(std::vector<nix::Tag>, nix::Source, referringTags))
272272
.reg("referringMultiTags", GETTER(std::vector<nix::MultiTag>, nix::Source, referringMultiTags));
273273
methods->add("Source::openSourceIdx", nixsource::openSourceIdx);
274+
methods->add("Source::compare", nixsource::compare);
274275

275276
classdef<nix::Tag>("Tag", methods)
276277
.desc(&nixtag::describe)

src/nixsource.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ namespace nixsource {
3333
output.set(0, currObj.getSource(idx));
3434
}
3535

36+
void compare(const extractor &input, infusor &output) {
37+
nix::Source currObj = input.entity<nix::Source>(1);
38+
nix::Source other = input.entity<nix::Source>(2);
39+
output.set(0, currObj.compare(other));
40+
}
41+
3642
} // namespace nixsource

src/nixsource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace nixsource {
1717

1818
void openSourceIdx(const extractor &input, infusor &output);
1919

20+
void compare(const extractor &input, infusor &output);
21+
2022
} // namespace nixsource
2123

2224
#endif

tests/TestSource.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
funcs{end+1} = @test_referring_data_arrays;
2626
funcs{end+1} = @test_referring_tags;
2727
funcs{end+1} = @test_referring_multi_tags;
28+
funcs{end+1} = @test_compare;
2829
end
2930

3031
%% Test: fetch sources
@@ -282,3 +283,18 @@
282283
t2.add_source(s);
283284
assert(size(s.referring_multi_tags, 1) == 2);
284285
end
286+
287+
function [] = test_compare( varargin )
288+
%% Test: Compare Source entities
289+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
290+
b1 = f.create_block('testBlock1', 'nixBlock');
291+
b2 = f.create_block('testBlock2', 'nixBlock');
292+
s1 = b1.create_source('testSource1', 'nixSource');
293+
s2 = b1.create_source('testSource2', 'nixSource');
294+
s3 = b2.create_source('testSource1', 'nixSource');
295+
296+
assert(s1.compare(s2) < 0);
297+
assert(s1.compare(s1) == 0);
298+
assert(s2.compare(s1) > 0);
299+
assert(s1.compare(s3) ~= 0);
300+
end

0 commit comments

Comments
 (0)