Skip to content

Commit acda83d

Browse files
committed
add set/remove link section for section
1 parent 6e57f03 commit acda83d

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

+nix/Section.m

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,32 @@
3434
section = nix.Section(handle);
3535
end;
3636
end;
37-
38-
function section = link(obj)
39-
handle = nix_mx('Section::link', obj.nix_handle);
37+
38+
% ----------------
39+
% Link methods
40+
% ----------------
41+
42+
function [] = set_link(obj, val)
43+
if (isempty(val))
44+
nix_mx('Section::set_none_link', obj.nix_handle);
45+
else
46+
if(strcmp(class(val), 'nix.Section'))
47+
addID = val.id;
48+
else
49+
addID = val;
50+
end;
51+
nix_mx('Section::set_link', obj.nix_handle, addID);
52+
end;
53+
end;
54+
55+
function section = openLink(obj)
56+
handle = nix_mx('Section::openLink', obj.nix_handle);
4057
section = {};
4158
if handle ~= 0
4259
section = nix.Section(handle);
4360
end;
4461
end;
45-
62+
4663
% ----------------
4764
% Section methods
4865
% ----------------

nix_mx.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ void mexFunction(int nlhs,
212212
.reg("openSection", GETBYSTR(nix::Section, nix::Section, getSection))
213213
.reg("hasProperty", GETBYSTR(bool, nix::Section, hasProperty))
214214
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
215-
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
215+
.reg("openLink", GETCONTENT(nix::Section, nix::Section, link))
216+
.reg("set_link", SETTER(const std::string&, nix::Section, link))
217+
.reg("set_none_link", SETTER(const boost::none_t, nix::Section, link))
216218
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent))
217219
.reg("set_type", SETTER(const std::string&, nix::Section, type))
218220
.reg("set_definition", SETTER(const std::string&, nix::Section, definition))

tests/TestSection.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
funcs{end+1} = @test_has_section;
1212
funcs{end+1} = @test_attrs;
1313
funcs{end+1} = @test_properties;
14+
funcs{end+1} = @test_link;
1415
end
1516

1617
%% Test: Create Section
@@ -133,3 +134,20 @@
133134

134135
assert(isempty(f.sections{3}.allProperties));
135136
end
137+
138+
%%Test: set, open and remove section link
139+
function [] = test_link( varargin )
140+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
141+
mainSec = f.createSection('mainSection', 'nixSection');
142+
tmp = f.createSection('linkSection1', 'nixSection');
143+
tmp = f.createSection('linkSection2', 'nixSection');
144+
145+
assert(isempty(mainSec.openLink));
146+
mainSec.set_link(f.sections{3}.id);
147+
assert(strcmp(mainSec.openLink.name, 'linkSection2'));
148+
mainSec.set_link(f.sections{2});
149+
assert(strcmp(mainSec.openLink.name, 'linkSection1'));
150+
151+
mainSec.set_link('');
152+
assert(isempty(mainSec.openLink));
153+
end

0 commit comments

Comments
 (0)