Skip to content

Commit d9931dd

Browse files
committed
create and delete nested source
1 parent 763279f commit d9931dd

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

+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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ void mexFunction(int nlhs,
128128

129129
classdef<nix::Source>("Source", methods)
130130
.desc(&nixsource::describe)
131+
.reg("createSource", &nix::Source::createSource)
132+
.reg("deleteSource", REMOVER(nix::Source, nix::Source, deleteSource))
131133
.reg("sources", &nix::Source::sources)
132134
.reg("openSource", GETBYSTR(nix::Source, nix::Source, getSource))
133135
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata));

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)