Skip to content

Commit 97577a8

Browse files
committed
add create/remove section for section
1 parent 2b1e18f commit 97577a8

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

+nix/Section.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
% Section methods
4848
% ----------------
4949

50+
function newSec = createSection(obj, name, type)
51+
newSec = nix.Section(nix_mx('Section::createSection', obj.nix_handle, name, type));
52+
obj.sectionsCache.lastUpdate = 0;
53+
end;
54+
55+
function delCheck = deleteSection(obj, del)
56+
delCheck = nix.Utils.delete_entity(obj, del, 'nix.Section', 'Section::deleteSection');
57+
obj.sectionsCache.lastUpdate = 0;
58+
end;
59+
5060
function retObj = open_section(obj, id_or_name)
5161
retObj = nix.Utils.open_entity(obj, ...
5262
'Section::openSection', id_or_name, @nix.Section);

nix_mx.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ void mexFunction(int nlhs,
188188
.reg("hasProperty", GETBYSTR(bool, nix::Section, hasProperty))
189189
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
190190
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
191-
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent));
191+
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent))
192+
.reg("createSection", &nix::Section::createSection)
193+
.reg("deleteSection", REMOVER(nix::Section, nix::Section, deleteSection));
192194
//.reg("set_repository", SETTER(const std::string&, nix::Section, repository));
193195
methods->add("Section::properties", nixsection::properties);
194196

tests/TestSection.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
% Detailed explanation goes here
44

55
funcs = {};
6+
funcs{end+1} = @test_create_section;
7+
funcs{end+1} = @test_delete_section;
68
funcs{end+1} = @test_list_subsections;
79
funcs{end+1} = @test_open_section;
810
funcs{end+1} = @test_parent;
@@ -11,6 +13,32 @@
1113
funcs{end+1} = @test_properties;
1214
end
1315

16+
%% Test: Create Section
17+
function [] = test_create_section( varargin )
18+
f = nix.File(fullfile(pwd,'tests','testRW.h5'), nix.FileMode.Overwrite);
19+
s = f.createSection('mainSection', 'nixSection');
20+
21+
assert(isempty(s.sections));
22+
tmp = s.createSection('testSection1', 'nixSection');
23+
tmp = s.createSection('testSection2', 'nixSection');
24+
assert(size(s.sections, 1) == 2);
25+
end
26+
27+
%% Test: Delete Section by entity or ID
28+
function [] = test_delete_section( varargin )
29+
f = nix.File(fullfile(pwd,'tests','testRW.h5'), nix.FileMode.Overwrite);
30+
s = f.createSection('mainSection', 'nixSection');
31+
tmp = s.createSection('testSection1', 'nixSection');
32+
tmp = s.createSection('testSection2', 'nixSection');
33+
34+
assert(s.deleteSection(s.sections{2}.id));
35+
assert(size(s.sections, 1) == 1);
36+
assert(s.deleteSection(s.sections{1}));
37+
assert(isempty(s.sections));
38+
39+
assert(~s.deleteSection('I do not exist'));
40+
end
41+
1442
function [] = test_list_subsections( varargin )
1543
%% Test: List/fetch subsections
1644
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);

0 commit comments

Comments
 (0)