Skip to content

Commit 048a855

Browse files
committed
Merge pull request #75 from mpsonntag/createDelete
Setter for metadata sections
2 parents aab09cb + e83b360 commit 048a855

File tree

7 files changed

+145
-48
lines changed

7 files changed

+145
-48
lines changed

+nix/MetadataMixIn.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@
2323
strcat(obj.alias, '::openMetadataSection'), ...
2424
obj.nix_handle, obj.metadataCache, @nix.Section);
2525
end;
26-
end
26+
27+
function set_metadata(obj, val)
28+
if (isempty(val))
29+
nix_mx(strcat(obj.alias, '::set_none_metadata'), obj.nix_handle, val);
30+
else
31+
obj.metadataCache = nix.Utils.add_entity(obj, val, 'nix.Section', ...
32+
strcat(obj.alias, '::set_metadata'), obj.metadataCache);
33+
end;
34+
obj.metadataCache.lastUpdate = 0;
35+
end;
36+
end;
2737

2838
end
2939

nix_mx.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void mexFunction(int nlhs,
117117
.reg("openTag", GETBYSTR(nix::Tag, nix::Block, getTag))
118118
.reg("openMultiTag", GETBYSTR(nix::MultiTag, nix::Block, getMultiTag))
119119
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Block, metadata))
120+
.reg("set_metadata", SETTER(const std::string&, nix::Block, metadata))
121+
.reg("set_none_metadata", SETTER(const boost::none_t, nix::Block, metadata))
120122
.reg("deleteDataArray", REMOVER(nix::DataArray, nix::Block, deleteDataArray))
121123
.reg("deleteSource", REMOVER(nix::Source, nix::Block, deleteSource))
122124
.reg("deleteTag", REMOVER(nix::Tag, nix::Block, deleteTag))
@@ -131,7 +133,9 @@ void mexFunction(int nlhs,
131133
.desc(&nixdataarray::describe)
132134
.reg("sources", IDATAARRAY(std::vector<nix::Source>, EntityWithSources, std::function<bool(const nix::Source &)>, sources, const))
133135
.reg("openMetadataSection", IDATAARRAY(nix::Section, EntityWithMetadata, , metadata, const))
134-
.reg("set_type", IDATAARRAY(void, NamedEntity, const std::string&, type,))
136+
.reg("set_metadata", IDATAARRAY(void, EntityWithMetadata, const std::string&, metadata, ))
137+
.reg("set_none_metadata", IDATAARRAY(void, EntityWithMetadata, const boost::none_t, metadata, ))
138+
.reg("set_type", IDATAARRAY(void, NamedEntity, const std::string&, type, ))
135139
.reg("set_definition", IDATAARRAY(void, NamedEntity, const std::string&, definition, ))
136140
.reg("set_none_definition", IDATAARRAY(void, NamedEntity, const boost::none_t, definition, ))
137141
.reg("set_label", SETTER(const std::string&, nix::DataArray, label))
@@ -151,6 +155,8 @@ void mexFunction(int nlhs,
151155
.reg("sources", &nix::Source::sources)
152156
.reg("openSource", GETBYSTR(nix::Source, nix::Source, getSource))
153157
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata))
158+
.reg("set_metadata", SETTER(const std::string&, nix::Source, metadata))
159+
.reg("set_none_metadata", SETTER(const boost::none_t, nix::Source, metadata))
154160
.reg("set_type", SETTER(const std::string&, nix::Source, type))
155161
.reg("set_definition", SETTER(const std::string&, nix::Source, definition))
156162
.reg("set_none_definition", SETTER(const boost::none_t, nix::Source, definition));
@@ -164,6 +170,8 @@ void mexFunction(int nlhs,
164170
.reg("openFeature", GETBYSTR(nix::Feature, nix::Tag, getFeature))
165171
.reg("openSource", GETBYSTR(nix::Source, nix::Tag, getSource))
166172
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Tag, metadata))
173+
.reg("set_metadata", SETTER(const std::string&, nix::Tag, metadata))
174+
.reg("set_none_metadata", SETTER(const boost::none_t, nix::Tag, metadata))
167175
.reg("removeReference", REMOVER(nix::DataArray, nix::Tag, removeReference))
168176
.reg("removeSource", REMOVER(nix::Source, nix::Tag, removeSource))
169177
.reg("deleteFeature", REMOVER(nix::Feature, nix::Tag, deleteFeature));
@@ -185,6 +193,8 @@ void mexFunction(int nlhs,
185193
.reg("openFeature", GETBYSTR(nix::Feature, nix::MultiTag, getFeature))
186194
.reg("openSource", GETBYSTR(nix::Source, nix::MultiTag, getSource))
187195
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::MultiTag, metadata))
196+
.reg("set_metadata", SETTER(const std::string&, nix::MultiTag, metadata))
197+
.reg("set_none_metadata", SETTER(const boost::none_t, nix::MultiTag, metadata))
188198
.reg("removeReference", REMOVER(nix::DataArray, nix::MultiTag, removeReference))
189199
.reg("removeSource", REMOVER(nix::Source, nix::MultiTag, removeSource))
190200
.reg("deleteFeature", REMOVER(nix::Feature, nix::MultiTag, deleteFeature));

tests/TestBlock.m

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
funcs{end+1} = @test_open_source;
2424
funcs{end+1} = @test_has_multitag;
2525
funcs{end+1} = @test_has_tag;
26+
funcs{end+1} = @test_set_metadata;
2627
funcs{end+1} = @test_open_metadata;
2728
end
2829

@@ -345,15 +346,28 @@
345346
assert(~b.has_tag('I do not exist'));
346347
end
347348

349+
%% Test: Set metadata
350+
function [] = test_set_metadata ( varargin )
351+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
352+
tmp = f.createSection('testSection1', 'nixSection');
353+
tmp = f.createSection('testSection2', 'nixSection');
354+
b = f.createBlock('testBlock', 'nixBlock');
355+
356+
assert(isempty(b.open_metadata));
357+
b.set_metadata(f.sections{1});
358+
assert(strcmp(b.open_metadata.name, 'testSection1'));
359+
b.set_metadata(f.sections{2});
360+
assert(strcmp(b.open_metadata.name, 'testSection2'));
361+
b.set_metadata('');
362+
assert(isempty(b.open_metadata));
363+
end
364+
348365
function [] = test_open_metadata( varargin )
349366
%% Test: Open metadata
350-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
351-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
367+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
368+
tmp = f.createSection('testSection', 'nixSection');
369+
b = f.createBlock('testBlock', 'nixBlock');
370+
b.set_metadata(f.sections{1});
352371

353-
assert(isempty(getBlock.open_metadata()))
354-
355-
%-- ToDo implement test for exising metadata
356-
%getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
357-
%assert(~isempty(getBlock.open_metadata()))
358-
disp('Test Block: open existing metadata ... TODO (proper testfile)');
372+
assert(strcmp(b.open_metadata.name, 'testSection'));
359373
end

tests/TestDataArray.m

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
funcs = {};
66
funcs{end+1} = @test_attrs;
77
funcs{end+1} = @test_open_data;
8+
funcs{end+1} = @test_set_metadata;
89
funcs{end+1} = @test_open_metadata;
910
funcs{end+1} = @test_list_sources;
1011
funcs{end+1} = @test_set_data;
@@ -57,18 +58,32 @@
5758
assert(size(getDataArray.read_all(),2) == 36);
5859
end
5960

61+
%% Test: Set metadata
62+
function [] = test_set_metadata ( varargin )
63+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
64+
tmp = f.createSection('testSection1', 'nixSection');
65+
tmp = f.createSection('testSection2', 'nixSection');
66+
b = f.createBlock('testBlock', 'nixBlock');
67+
da = b.create_data_array('testDataArray', 'nixDataArray', 'double', [1 2]);
68+
69+
assert(isempty(da.open_metadata));
70+
da.set_metadata(f.sections{1});
71+
assert(strcmp(da.open_metadata.name, 'testSection1'));
72+
da.set_metadata(f.sections{2});
73+
assert(strcmp(da.open_metadata.name, 'testSection2'));
74+
da.set_metadata('');
75+
assert(isempty(da.open_metadata));
76+
end
77+
6078
%% Test: Open metadata
6179
function [] = test_open_metadata( varargin )
62-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
63-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
64-
65-
%-- ToDo implement test for empty metadata
66-
getDataArray = getBlock.data_array(getBlock.dataArrays{1,1}.id);
67-
%assert(isempty(getDataArray.open_metadata()))
68-
disp('Test DataArray: open empty metadata ... TODO (proper testfile)');
69-
70-
getDataArray = getBlock.data_array(getBlock.dataArrays{1,1}.id);
71-
assert(~isempty(getDataArray.open_metadata()))
80+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
81+
tmp = f.createSection('testSection', 'nixSection');
82+
b = f.createBlock('testBlock', 'nixBlock');
83+
da = b.create_data_array('testDataArray', 'nixDataArray', 'double', [1 2]);
84+
da.set_metadata(f.sections{1});
85+
86+
assert(strcmp(da.open_metadata.name, 'testSection'));
7287
end
7388

7489
%% Test: List sources

tests/TestMultiTag.m

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
funcs{end+1} = @test_open_positions;
2121
funcs{end+1} = @test_add_extents;
2222
funcs{end+1} = @test_open_extents;
23+
funcs{end+1} = @test_set_metadata;
2324
funcs{end+1} = @test_open_metadata;
2425
funcs{end+1} = @test_retrieve_data;
2526
funcs{end+1} = @test_retrieve_feature_data;
@@ -322,18 +323,34 @@
322323
disp('Test MultiTag: open existing extents ... TODO (proper testfile)');
323324
end
324325

326+
%% Test: Set metadata
327+
function [] = test_set_metadata ( varargin )
328+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
329+
tmp = f.createSection('testSection1', 'nixSection');
330+
tmp = f.createSection('testSection2', 'nixSection');
331+
b = f.createBlock('testBlock', 'nixBlock');
332+
tmp = b.create_data_array('testDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
333+
t = b.create_multi_tag('metadataTest', 'nixMultiTag', b.dataArrays{1});
334+
335+
assert(isempty(t.open_metadata));
336+
t.set_metadata(f.sections{1});
337+
assert(strcmp(t.open_metadata.name, 'testSection1'));
338+
t.set_metadata(f.sections{2});
339+
assert(strcmp(t.open_metadata.name, 'testSection2'));
340+
t.set_metadata('');
341+
assert(isempty(t.open_metadata));
342+
end
343+
325344
%% Test: Open metadata
326345
function [] = test_open_metadata( varargin )
327-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
328-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
329-
330-
getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{1,1}.id);
331-
assert(isempty(getMultiTag.open_metadata()))
332-
333-
%-- ToDo implement test for existing metadata
334-
%getMultiTag = getBlock.open_multi_tag(getBlock.multiTags{2,1}.id);
335-
%assert(~isempty(getMultiTag.open_metadata()));
336-
disp('Test MultiTag: open existing metadata ... TODO (proper testfile)');
346+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
347+
tmp = f.createSection('testSection', 'nixSection');
348+
b = f.createBlock('testBlock', 'nixBlock');
349+
tmp = b.create_data_array('testDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
350+
t = b.create_multi_tag('metadataTest', 'nixMultiTag', b.dataArrays{1});
351+
t.set_metadata(f.sections{1});
352+
353+
assert(strcmp(t.open_metadata.name, 'testSection'));
337354
end
338355

339356
%% Test: Retrieve data

tests/TestSource.m

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
funcs{end+1} = @test_attrs;
99
funcs{end+1} = @test_fetch_sources;
1010
funcs{end+1} = @test_open_source;
11+
funcs{end+1} = @test_set_metadata;
1112
funcs{end+1} = @test_open_metadata;
1213
end
1314

@@ -43,18 +44,32 @@
4344
assert(isempty(getNonSource));
4445
end
4546

47+
%% Test: Set metadata
48+
function [] = test_set_metadata ( varargin )
49+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
50+
tmp = f.createSection('testSection1', 'nixSection');
51+
tmp = f.createSection('testSection2', 'nixSection');
52+
b = f.createBlock('testBlock', 'nixBlock');
53+
s = b.create_source('testSource', 'nixSource');
54+
55+
assert(isempty(s.open_metadata));
56+
s.set_metadata(f.sections{1});
57+
assert(strcmp(s.open_metadata.name, 'testSection1'));
58+
s.set_metadata(f.sections{2});
59+
assert(strcmp(s.open_metadata.name, 'testSection2'));
60+
s.set_metadata('');
61+
assert(isempty(s.open_metadata));
62+
end
63+
4664
%% Test: Open metadata
4765
function [] = test_open_metadata( varargin )
48-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
49-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
50-
51-
getSource = getBlock.open_source(getBlock.sources{1,1}.id);
52-
assert(isempty(getSource.open_metadata()))
53-
54-
%-- ToDo implement test for empty metadata
55-
%getSource = getBlock.open_source(getBlock.sources{1,1}.id);
56-
%assert(~isempty(getSource.open_metadata()))
57-
disp('Test Source: open existing metadata ... TODO (proper testfile)');
66+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
67+
tmp = f.createSection('testSection', 'nixSection');
68+
b = f.createBlock('testBlock', 'nixBlock');
69+
s = b.create_source('testSource', 'nixSource');
70+
s.set_metadata(f.sections{1});
71+
72+
assert(strcmp(s.open_metadata.name, 'testSection'));
5873
end
5974

6075
%% Test: create source

tests/TestTag.m

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
funcs{end+1} = @test_open_source;
1616
funcs{end+1} = @test_open_feature;
1717
funcs{end+1} = @test_open_reference;
18+
funcs{end+1} = @test_set_metadata;
1819
funcs{end+1} = @test_open_metadata;
1920
funcs{end+1} = @test_retrieve_data;
2021
funcs{end+1} = @test_retrieve_feature_data;
@@ -245,17 +246,32 @@
245246
assert(isempty(getNonRef));
246247
end
247248

249+
%% Test: Set metadata
250+
function [] = test_set_metadata ( varargin )
251+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
252+
tmp = f.createSection('testSection1', 'nixSection');
253+
tmp = f.createSection('testSection2', 'nixSection');
254+
b = f.createBlock('testBlock', 'nixBlock');
255+
t = b.create_tag('testTag', 'nixTag', [1, 2, 3, 4]);
256+
257+
assert(isempty(t.open_metadata));
258+
t.set_metadata(f.sections{1});
259+
assert(strcmp(t.open_metadata.name, 'testSection1'));
260+
t.set_metadata(f.sections{2});
261+
assert(strcmp(t.open_metadata.name, 'testSection2'));
262+
t.set_metadata('');
263+
assert(isempty(t.open_metadata));
264+
end
248265

249266
%% Test: Open metadata
250267
function [] = test_open_metadata( varargin )
251-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
252-
getBlock = test_file.openBlock(test_file.blocks{1,1}.name);
253-
254-
getTag = getBlock.open_tag(getBlock.tags{1,1}.id);
255-
assert(isempty(getTag.open_metadata()))
256-
257-
getTag = getBlock.open_tag(getBlock.tags{2,1}.id);
258-
assert(~isempty(getTag.open_metadata()));
268+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
269+
tmp = f.createSection('testSection', 'nixSection');
270+
b = f.createBlock('testBlock', 'nixBlock');
271+
t = b.create_tag('testTag', 'nixTag', [1, 2, 3, 4]);
272+
273+
t.set_metadata(f.sections{1});
274+
assert(strcmp(t.open_metadata.name, 'testSection'));
259275
end
260276

261277
%% Test: Retrieve data

0 commit comments

Comments
 (0)