Skip to content

Commit eb5b9a4

Browse files
committed
Merge pull request #76 from mpsonntag/createDelete
Add setter methods for Section
2 parents 048a855 + acda83d commit eb5b9a4

File tree

4 files changed

+72
-40
lines changed

4 files changed

+72
-40
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,13 @@ 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))
219+
.reg("set_type", SETTER(const std::string&, nix::Section, type))
220+
.reg("set_definition", SETTER(const std::string&, nix::Section, definition))
221+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Section, definition))
217222
.reg("set_repository", SETTER(const std::string&, nix::Section, repository))
218223
.reg("set_none_repository", SETTER(const boost::none_t, nix::Section, repository))
219224
.reg("set_mapping", SETTER(const std::string&, nix::Section, mapping))

src/nixsection.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ namespace nixsection {
1414
mxArray *describe(const nix::Section &section)
1515
{
1616
struct_builder sb({ 1 }, {
17-
"name", "id", "type", "repository", "mapping"
17+
"name", "id", "type", "definition", "repository", "mapping"
1818
});
1919

2020
sb.set(section.name());
2121
sb.set(section.id());
2222
sb.set(section.type());
23+
sb.set(section.definition());
2324
sb.set(section.repository());
2425
sb.set(section.mapping());
2526

tests/TestSection.m

Lines changed: 43 additions & 34 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
@@ -89,40 +90,31 @@
8990
function [] = test_attrs( varargin )
9091
%% Test: Access Attributes / Links
9192
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
92-
s1 = f.createSection('foo', 'bar');
93-
94-
assert(strcmp(s1.name, 'foo'));
95-
assert(strcmp(s1.type, 'bar'));
96-
assert(isempty(s1.repository));
97-
assert(isempty(s1.mapping));
98-
99-
s1.repository = 'rep1';
100-
s1.mapping = 'map1';
101-
assert(strcmp(s1.repository, 'rep1'));
102-
assert(strcmp(s1.mapping, 'map1'));
103-
104-
s1.repository = '';
105-
s1.mapping = '';
106-
assert(isempty(s1.repository));
107-
assert(isempty(s1.mapping));
108-
109-
assert(isempty(s1.link));
110-
111-
% TODO rewrite tests for link / parent
112-
113-
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
114-
s1 = f.sections{3};
115-
116-
assert(strcmp(s1.name, 'Sessions'));
117-
assert(strcmp(s1.type, 'nix.metadata.section'));
118-
assert(isempty(s1.repository));
119-
assert(isempty(s1.mapping));
120-
121-
subj = s1.sections{1}.sections{1}.link;
122-
assert(strcmp(subj.name, 'Subject'));
123-
124-
emp_ty = s1.sections{1}.link;
125-
assert(isempty(emp_ty));
93+
s = f.createSection('foo', 'bar');
94+
95+
assert(~isempty(s.id));
96+
97+
assert(strcmp(s.name, 'foo'));
98+
assert(strcmp(s.type, 'bar'));
99+
assert(isempty(s.repository));
100+
assert(isempty(s.mapping));
101+
assert(isempty(s.definition));
102+
103+
s.type = 'nixBlock';
104+
s.definition = 'section definition';
105+
s.repository = 'rep1';
106+
s.mapping = 'map1';
107+
assert(strcmp(s.type, 'nixBlock'));
108+
assert(strcmp(s.definition, 'section definition'));
109+
assert(strcmp(s.repository, 'rep1'));
110+
assert(strcmp(s.mapping, 'map1'));
111+
112+
s.definition = '';
113+
s.repository = '';
114+
s.mapping = '';
115+
assert(isempty(s.definition));
116+
assert(isempty(s.repository));
117+
assert(isempty(s.mapping));
126118
end
127119

128120
function [] = test_properties( varargin )
@@ -142,3 +134,20 @@
142134

143135
assert(isempty(f.sections{3}.allProperties));
144136
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)