Skip to content

Commit 9d8e170

Browse files
committed
Merge pull request #72 from mpsonntag/createDelete
Add setter methods for Block and Source
2 parents d89c722 + 3fc3d35 commit 9d8e170

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

nix_mx.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ void mexFunction(int nlhs,
118118
.reg("deleteDataArray", REMOVER(nix::DataArray, nix::Block, deleteDataArray))
119119
.reg("deleteSource", REMOVER(nix::Source, nix::Block, deleteSource))
120120
.reg("deleteTag", REMOVER(nix::Tag, nix::Block, deleteTag))
121-
.reg("deleteMultiTag", REMOVER(nix::MultiTag, nix::Block, deleteMultiTag));
121+
.reg("deleteMultiTag", REMOVER(nix::MultiTag, nix::Block, deleteMultiTag))
122+
.reg("set_type", SETTER(const std::string&, nix::Block, type))
123+
.reg("set_definition", SETTER(const std::string&, nix::Block, definition))
124+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Block, definition));
122125
methods->add("Block::createDataArray", nixblock::create_data_array);
123126
methods->add("Block::createMultiTag", nixblock::create_multi_tag);
124127

@@ -138,7 +141,10 @@ void mexFunction(int nlhs,
138141
.reg("deleteSource", REMOVER(nix::Source, nix::Source, deleteSource))
139142
.reg("sources", &nix::Source::sources)
140143
.reg("openSource", GETBYSTR(nix::Source, nix::Source, getSource))
141-
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata));
144+
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata))
145+
.reg("set_type", SETTER(const std::string&, nix::Source, type))
146+
.reg("set_definition", SETTER(const std::string&, nix::Source, definition))
147+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Source, definition));
142148

143149
classdef<nix::Tag>("Tag", methods)
144150
.desc(&nixtag::describe)

tests/TestBlock.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@
2929
function [] = test_attrs( varargin )
3030
%% Test: Access Attributes
3131
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
32-
b = f.createBlock('tagtest', 'nixBlock');
32+
b = f.createBlock('tagtest', 'test nixBlock');
3333

3434
assert(~isempty(b.id));
3535
assert(strcmp(b.name, 'tagtest'));
36+
assert(strcmp(b.type, 'test nixBlock'));
37+
38+
b.type = 'nixBlock';
3639
assert(strcmp(b.type, 'nixBlock'));
40+
41+
assert(isempty(b.definition));
42+
b.definition = 'block definition';
43+
assert(strcmp(b.definition, 'block definition'));
44+
45+
b.definition = '';
3746
assert(isempty(b.definition));
3847
end
3948

tests/TestSource.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
funcs = {};
66
funcs{end+1} = @test_create_source;
77
funcs{end+1} = @test_delete_source;
8+
funcs{end+1} = @test_attrs;
89
funcs{end+1} = @test_fetch_sources;
910
funcs{end+1} = @test_open_source;
1011
funcs{end+1} = @test_open_metadata;
@@ -83,3 +84,24 @@
8384
assert(~getSource.delete_source('I do not exist'));
8485
assert(isempty(getSource.sources));
8586
end
87+
88+
function [] = test_attrs( varargin )
89+
%% Test: Access Attributes
90+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
91+
b = f.createBlock('tagtest', 'test nixBlock');
92+
s = b.create_source('sourcetest', 'test nixSource');
93+
94+
assert(~isempty(s.id));
95+
assert(strcmp(s.name, 'sourcetest'));
96+
assert(strcmp(s.type, 'test nixSource'));
97+
98+
s.type = 'nixSource';
99+
assert(strcmp(s.type, 'nixSource'));
100+
101+
assert(isempty(s.definition));
102+
s.definition = 'source definition';
103+
assert(strcmp(s.definition, 'source definition'));
104+
105+
s.definition = '';
106+
assert(isempty(s.definition));
107+
end

0 commit comments

Comments
 (0)