Skip to content

Commit 3aa963c

Browse files
committed
[c++/m] Add Tag multiple entities create
Adds references and sources multiple entity create methods to the Tag entity and introduces tests for all added methods.
1 parent b0bd322 commit 3aa963c

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

+nix/Tag.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
'nix.DataArray', 'Tag::addReference');
4040
end;
4141

42+
function [] = add_references(obj, add_cell_array)
43+
nix.Utils.add_entity_array(obj, add_cell_array, ...
44+
'nix.DataArray', strcat(obj.alias, '::addReferences'));
45+
end
46+
4247
function hasRef = has_reference(obj, id_or_name)
4348
hasRef = nix_mx('Tag::hasReference', obj.nix_handle, id_or_name);
4449
end;

nix_mx.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ void mexFunction(int nlhs,
276276
methods->add("Tag::retrieveData", nixtag::retrieveData);
277277
methods->add("Tag::featureRetrieveData", nixtag::retrieveFeatureData);
278278
methods->add("Tag::addReference", nixtag::addReference);
279+
methods->add("Tag::addReferences", nixtag::addReferences);
279280
methods->add("Tag::addSource", nixtag::addSource);
281+
methods->add("Tag::addSources", nixtag::addSources);
280282
methods->add("Tag::createFeature", nixtag::createFeature);
281283

282284
classdef<nix::MultiTag>("MultiTag", methods)

src/nixtag.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,23 @@ namespace nixtag {
3838
currObj.addReference(input.str(2));
3939
}
4040

41+
void addReferences(const extractor &input, infusor &output) {
42+
nix::Tag currObj = input.entity<nix::Tag>(1);
43+
std::vector<nix::DataArray> curr = input.entity_vec<nix::DataArray>(2);
44+
currObj.references(curr);
45+
}
46+
4147
void addSource(const extractor &input, infusor &output) {
4248
nix::Tag currObj = input.entity<nix::Tag>(1);
4349
currObj.addSource(input.str(2));
4450
}
4551

52+
void addSources(const extractor &input, infusor &output) {
53+
nix::Tag currObj = input.entity<nix::Tag>(1);
54+
std::vector<nix::Source> curr = input.entity_vec<nix::Source>(2);
55+
currObj.sources(curr);
56+
}
57+
4658
void createFeature(const extractor &input, infusor &output) {
4759
nix::Tag currObj = input.entity<nix::Tag>(1);
4860

src/nixtag.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ namespace nixtag {
1717

1818
void addReference(const extractor &input, infusor &output);
1919

20+
void addReferences(const extractor &input, infusor &output);
21+
2022
void addSource(const extractor &input, infusor &output);
2123

24+
void addSources(const extractor &input, infusor &output);
25+
2226
void createFeature(const extractor &input, infusor &output);
2327

2428
void retrieveData(const extractor &input, infusor &output);

tests/TestTag.m

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
funcs = {};
1414
funcs{end+1} = @test_add_source;
15+
funcs{end+1} = @test_add_sources;
1516
funcs{end+1} = @test_remove_source;
1617
funcs{end+1} = @test_add_reference;
18+
funcs{end+1} = @test_add_references;
1719
funcs{end+1} = @test_remove_reference;
1820
funcs{end+1} = @test_add_feature;
1921
funcs{end+1} = @test_remove_feature;
@@ -59,6 +61,40 @@
5961
assert(size(f.blocks{1}.tags{1}.sources, 1) == 2);
6062
end
6163

64+
%% Test: Add sources by entity cell array
65+
function [] = test_add_sources ( varargin )
66+
testFile = fullfile(pwd, 'tests', 'testRW.h5');
67+
f = nix.File(testFile, nix.FileMode.Overwrite);
68+
b = f.create_block('testBlock', 'nixBlock');
69+
t = b.create_tag('testTag', 'nixTag', [1 2]);
70+
tmp = b.create_source('testSource1', 'nixSource');
71+
tmp = b.create_source('testSource2', 'nixSource');
72+
tmp = b.create_source('testSource3', 'nixSource');
73+
74+
assert(isempty(t.sources));
75+
76+
try
77+
t.add_sources('hurra');
78+
catch ME
79+
assert(strcmp(ME.message, 'Expected cell array'));
80+
end;
81+
assert(isempty(t.sources));
82+
83+
try
84+
t.add_sources({12, 13});
85+
catch ME
86+
assert(~isempty(strfind(ME.message, 'not a nix.Source')));
87+
end;
88+
assert(isempty(t.sources));
89+
90+
t.add_sources(b.sources());
91+
assert(size(t.sources, 1) == 3);
92+
93+
clear t tmp b f;
94+
f = nix.File(testFile, nix.FileMode.ReadOnly);
95+
assert(size(f.blocks{1}.tags{1}.sources, 1) == 3);
96+
end
97+
6298
%% Test: Remove sources by entity and id
6399
function [] = test_remove_source ( varargin )
64100
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
@@ -104,6 +140,40 @@
104140
assert(size(f.blocks{1}.tags{1}.references, 1) == 2);
105141
end
106142

143+
%% Test: Add references by entity cell array
144+
function [] = test_add_references ( varargin )
145+
testFile = fullfile(pwd, 'tests', 'testRW.h5');
146+
f = nix.File(testFile, nix.FileMode.Overwrite);
147+
b = f.create_block('testBlock', 'nixBlock');
148+
t = b.create_tag('testTag', 'nixTag', [1 2]);
149+
tmp = b.create_data_array('referenceTest1', 'nixDataArray', nix.DataType.Double, [1 2]);
150+
tmp = b.create_data_array('referenceTest2', 'nixDataArray', nix.DataType.Double, [3 4]);
151+
tmp = b.create_data_array('referenceTest3', 'nixDataArray', nix.DataType.Double, [3 4]);
152+
153+
assert(isempty(t.references));
154+
155+
try
156+
t.add_references('hurra');
157+
catch ME
158+
assert(strcmp(ME.message, 'Expected cell array'));
159+
end;
160+
assert(isempty(t.references));
161+
162+
try
163+
t.add_references({12, 13});
164+
catch ME
165+
assert(~isempty(strfind(ME.message, 'not a nix.DataArray')));
166+
end;
167+
assert(isempty(t.references));
168+
169+
t.add_references(b.dataArrays);
170+
assert(size(t.references, 1) == 3);
171+
172+
clear t tmp b f;
173+
f = nix.File(testFile, nix.FileMode.ReadOnly);
174+
assert(size(f.blocks{1}.tags{1}.references, 1) == 3);
175+
end
176+
107177
%% Test: Remove references by entity and id
108178
function [] = test_remove_reference ( varargin )
109179
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);

0 commit comments

Comments
 (0)