Skip to content

Commit 6e57f03

Browse files
committed
add setters for section
1 parent 048a855 commit 6e57f03

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

nix_mx.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ void mexFunction(int nlhs,
214214
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
215215
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
216216
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent))
217+
.reg("set_type", SETTER(const std::string&, nix::Section, type))
218+
.reg("set_definition", SETTER(const std::string&, nix::Section, definition))
219+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Section, definition))
217220
.reg("set_repository", SETTER(const std::string&, nix::Section, repository))
218221
.reg("set_none_repository", SETTER(const boost::none_t, nix::Section, repository))
219222
.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: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,40 +89,31 @@
8989
function [] = test_attrs( varargin )
9090
%% Test: Access Attributes / Links
9191
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));
92+
s = f.createSection('foo', 'bar');
93+
94+
assert(~isempty(s.id));
95+
96+
assert(strcmp(s.name, 'foo'));
97+
assert(strcmp(s.type, 'bar'));
98+
assert(isempty(s.repository));
99+
assert(isempty(s.mapping));
100+
assert(isempty(s.definition));
101+
102+
s.type = 'nixBlock';
103+
s.definition = 'section definition';
104+
s.repository = 'rep1';
105+
s.mapping = 'map1';
106+
assert(strcmp(s.type, 'nixBlock'));
107+
assert(strcmp(s.definition, 'section definition'));
108+
assert(strcmp(s.repository, 'rep1'));
109+
assert(strcmp(s.mapping, 'map1'));
110+
111+
s.definition = '';
112+
s.repository = '';
113+
s.mapping = '';
114+
assert(isempty(s.definition));
115+
assert(isempty(s.repository));
116+
assert(isempty(s.mapping));
126117
end
127118

128119
function [] = test_properties( varargin )

0 commit comments

Comments
 (0)