Skip to content

Commit b5f4ae6

Browse files
committed
Merge pull request #61 from mpsonntag/createDelete
Create and delete Source
2 parents 271589d + d9931dd commit b5f4ae6

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
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/Source.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,22 @@
5151
% ------------------
5252
% Sources methods
5353
% ------------------
54-
54+
55+
function s = create_source(obj, name, type)
56+
s = nix.Source(nix_mx('Source::createSource', obj.nix_handle, name, type));
57+
obj.sourcesCache.lastUpdate = 0;
58+
end;
59+
60+
function delCheck = delete_source(obj, del)
61+
if(strcmp(class(del),'nix.Source'))
62+
delID = del.id;
63+
else
64+
delID = del;
65+
end;
66+
delCheck = nix_mx('Source::deleteSource', obj.nix_handle, delID);
67+
obj.sourcesCache.lastUpdate = 0;
68+
end;
69+
5570
function retObj = open_source(obj, id_or_name)
5671
handle = nix_mx('Source::openSource', obj.nix_handle, id_or_name);
5772
retObj = {};

nix_mx.cc

Lines changed: 3 additions & 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)
@@ -127,6 +128,8 @@ void mexFunction(int nlhs,
127128

128129
classdef<nix::Source>("Source", methods)
129130
.desc(&nixsource::describe)
131+
.reg("createSource", &nix::Source::createSource)
132+
.reg("deleteSource", REMOVER(nix::Source, nix::Source, deleteSource))
130133
.reg("sources", &nix::Source::sources)
131134
.reg("openSource", GETBYSTR(nix::Source, nix::Source, getSource))
132135
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata));

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

tests/TestSource.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
funcs{end+1} = @test_list_fetch_sources;
77
funcs{end+1} = @test_open_source;
88
funcs{end+1} = @test_open_metadata;
9+
funcs{end+1} = @test_create_source;
10+
funcs{end+1} = @test_delete_source;
911
end
1012

1113
%% Test: List/fetch sources
@@ -53,3 +55,30 @@
5355
disp('Test Source: open existing metadata ... TODO (proper testfile)');
5456
end
5557

58+
%% Test: create source
59+
function [] = test_create_source ( varargin )
60+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
61+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
62+
getSource = getBlock.create_source('sourcetest','nixsource');
63+
assert(isempty(getSource.sources));
64+
65+
createSource = getSource.create_source('nestedsource','nixsource');
66+
assert(~isempty(getSource.sources));
67+
assert(strcmp(createSource.name, 'nestedsource'));
68+
assert(strcmp(createSource.type, 'nixsource'));
69+
end
70+
71+
%% Test: delete source
72+
function [] = test_delete_source( varargin )
73+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
74+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
75+
getSource = getBlock.create_source('sourcetest','nixsource');
76+
assert(isempty(getSource.sources));
77+
78+
createSource1 = getSource.create_source('nestedsource1','nixsource');
79+
createSource2 = getSource.create_source('nestedsource2','nixsource');
80+
assert(getSource.delete_source('nestedsource1'));
81+
assert(getSource.delete_source(getSource.sources{1}.id));
82+
assert(~getSource.delete_source('I do not exist'));
83+
assert(isempty(getSource.sources));
84+
end

0 commit comments

Comments
 (0)