Skip to content

Commit 763279f

Browse files
committed
create and delete Blocksource
1 parent 271589d commit 763279f

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

+nix/Block.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@
5454
% Sources methods
5555
% -----------------
5656

57+
function s = create_source(obj, name, type)
58+
s = nix.Source(nix_mx('Block::createSource', obj.nix_handle, name, type));
59+
obj.sourcesCache.lastUpdate = 0;
60+
end;
61+
62+
function delCheck = delete_source(obj, del)
63+
if(strcmp(class(del),'nix.Source'))
64+
delID = del.id;
65+
else
66+
delID = del;
67+
end;
68+
delCheck = nix_mx('Block::deleteSource', obj.nix_handle, delID);
69+
obj.sourcesCache.lastUpdate = 0;
70+
end;
71+
5772
function retObj = open_source(obj, id_or_name)
5873
handle = nix_mx('Block::openSource', obj.nix_handle, id_or_name);
5974
retObj = {};

nix_mx.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void mexFunction(int nlhs,
103103
.desc(&nixblock::describe)
104104
.reg("dataArrays", &nix::Block::dataArrays)
105105
.reg("createSource", &nix::Block::createSource)
106+
.reg("deleteSource", REMOVER(nix::Source, nix::Block, deleteSource))
106107
//.reg("createDataArray", static_cast<nix::DataArray(nix::Block::*)(const std::string &, const std::string &, nix::DataType, const nix::NDSize &)>(&nix::Block::createDataArray))
107108
.reg("createTag", &nix::Block::createTag)
108109
.reg("createMultiTag", &nix::Block::createMultiTag)

tests/TestBlock.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
funcs{end+1} = @test_create_tag;
1919
funcs{end+1} = @test_create_data_array;
2020
funcs{end+1} = @test_create_data_array_from_data;
21+
funcs{end+1} = @test_create_source;
22+
funcs{end+1} = @test_delete_source;
2123
end
2224

2325
function [] = test_list_arrays( varargin )
@@ -210,3 +212,28 @@
210212

211213
assert(~isempty(b.dataArrays));
212214
end
215+
216+
%% Test: create source
217+
function [] = test_create_source ( varargin )
218+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
219+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
220+
assert(isempty(getBlock.sources));
221+
222+
createSource = getBlock.create_source('sourcetest','nixsource');
223+
assert(~isempty(getBlock.sources));
224+
assert(strcmp(createSource.name, 'sourcetest'));
225+
assert(strcmp(createSource.type, 'nixsource'));
226+
end
227+
228+
%% Test: delete source
229+
function [] = test_delete_source( varargin )
230+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
231+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
232+
createSource1 = getBlock.create_source('sourcetest1','nixsource');
233+
createSource2 = getBlock.create_source('sourcetest2','nixsource');
234+
235+
assert(getBlock.delete_source('sourcetest1'));
236+
assert(getBlock.delete_source(getBlock.sources{1}.id));
237+
assert(~getBlock.delete_source('I do not exist'));
238+
assert(isempty(getBlock.sources));
239+
end

0 commit comments

Comments
 (0)