Skip to content

Commit 1d3c030

Browse files
committed
[c++/m] Add Source parentSource method
Adds parentSource method to the Source entity on c++ and matlab side and adds a corresponding test.
1 parent 30ed627 commit 1d3c030

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

+nix/Source.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
retObj = nix.Utils.open_entity(obj, ...
4949
'Source::openSource', id_or_name, @nix.Source);
5050
end;
51-
51+
52+
function retObj = parent_source(obj)
53+
retObj = nix.Utils.fetchObj('Source::parentSource', ...
54+
obj.nix_handle, @nix.Source);
55+
end
5256
end;
5357
end

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ void mexFunction(int nlhs,
243243
.reg("setType", SETTER(const std::string&, nix::Source, type))
244244
.reg("setDefinition", SETTER(const std::string&, nix::Source, definition))
245245
.reg("setNoneDefinition", SETTER(const boost::none_t, nix::Source, definition))
246+
.reg("parentSource", GETTER(nix::Source, nix::Source, parentSource))
246247
.reg("sourceCount", GETTER(nix::ndsize_t, nix::Source, sourceCount));
247248

248249
classdef<nix::Tag>("Tag", methods)

tests/TestSource.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
funcs{end+1} = @test_has_source;
1919
funcs{end+1} = @test_open_source;
2020
funcs{end+1} = @test_source_count;
21+
funcs{end+1} = @test_parent_source;
2122
funcs{end+1} = @test_set_metadata;
2223
funcs{end+1} = @test_open_metadata;
2324
end
@@ -190,3 +191,18 @@
190191
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
191192
assert(f.blocks{1}.sources{1}.has_source(nestedID));
192193
end
194+
195+
%% Test: Get parent source
196+
function [] = test_parent_source( varargin )
197+
fileName = fullfile(pwd, 'tests', 'testRW.h5');
198+
f = nix.File(fileName, nix.FileMode.Overwrite);
199+
b = f.create_block('sourcetest', 'nixBlock');
200+
sourceName1 = 'testSource1';
201+
sourceName2 = 'testSource2';
202+
s1 = b.create_source(sourceName1, 'nixSource');
203+
s2 = s1.create_source(sourceName2, 'nixSource');
204+
s3 = s2.create_source('testSource3', 'nixSource');
205+
206+
assert(strcmp(s3.parent_source.name, sourceName2));
207+
assert(strcmp(s2.parent_source.name, sourceName1));
208+
end

0 commit comments

Comments
 (0)