Skip to content

Commit 7c05967

Browse files
committed
add/remove source/ref from tag
1 parent b5f4ae6 commit 7c05967

File tree

6 files changed

+155
-16
lines changed

6 files changed

+155
-16
lines changed

+nix/Tag.m

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@
8585
% References methods
8686
% ------------------
8787

88+
function [] = add_reference(obj, add_this)
89+
if(strcmp(class(add_this),'nix.DataArray'))
90+
addID = add_this.id;
91+
else
92+
addID = add_this;
93+
end;
94+
nix_mx('Tag::addReference', obj.nix_handle, addID);
95+
obj.referencesCache.lastUpdate = 0;
96+
end;
97+
98+
function delCheck = remove_reference(obj, del)
99+
if(strcmp(class(del),'nix.DataArray'))
100+
delID = del.id;
101+
else
102+
delID = del;
103+
end;
104+
delCheck = nix_mx('Tag::removeReference', obj.nix_handle, delID);
105+
obj.referencesCache.lastUpdate = 0;
106+
end;
107+
88108
function retObj = open_reference(obj, id_or_name)
89109
handle = nix_mx('Tag::openReferenceDataArray', obj.nix_handle, id_or_name);
90110
retObj = {};
@@ -138,7 +158,27 @@
138158
% ------------------
139159
% Sources methods
140160
% ------------------
141-
161+
162+
function [] = add_source(obj, add_this)
163+
if(strcmp(class(add_this),'nix.Source'))
164+
addID = add_this.id;
165+
else
166+
addID = add_this;
167+
end;
168+
nix_mx('Tag::addSource', obj.nix_handle, addID);
169+
obj.sourcesCache.lastUpdate = 0;
170+
end;
171+
172+
function delCheck = remove_source(obj, del)
173+
if(strcmp(class(del),'nix.Source'))
174+
delID = del.id;
175+
else
176+
delID = del;
177+
end;
178+
delCheck = nix_mx('Tag::removeSource', obj.nix_handle, delID);
179+
obj.sourcesCache.lastUpdate = 0;
180+
end;
181+
142182
function retObj = open_source(obj, id_or_name)
143183
handle = nix_mx('Tag::openSource', obj.nix_handle, id_or_name);
144184
retObj = {};

nix_mx.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ void mexFunction(int nlhs,
142142
.reg("openReferenceDataArray", GETBYSTR(nix::DataArray, nix::Tag, getReference))
143143
.reg("openFeature", GETBYSTR(nix::Feature, nix::Tag, getFeature))
144144
.reg("openSource", GETBYSTR(nix::Source, nix::Tag, getSource))
145-
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Tag, metadata));
145+
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Tag, metadata))
146+
.reg("removeReference", REMOVER(nix::DataArray, nix::Tag, removeReference))
147+
.reg("removeSource", REMOVER(nix::Source, nix::Tag, removeSource));
146148
methods->add("Tag::retrieveData", nixtag::retrieve_data);
147149
methods->add("Tag::featureRetrieveData", nixtag::retrieve_feature_data);
150+
methods->add("Tag::addReference", nixtag::add_reference);
151+
methods->add("Tag::addSource", nixtag::add_source);
148152

149153
classdef<nix::MultiTag>("MultiTag", methods)
150154
.desc(&nixmultitag::describe)

src/nixtag.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ namespace nixtag {
2626
return sb.array();
2727
}
2828

29+
void add_reference(const extractor &input, infusor &output)
30+
{
31+
nix::Tag currObj = input.entity<nix::Tag>(1);
32+
currObj.addReference(input.str(2));
33+
}
34+
35+
void add_source(const extractor &input, infusor &output)
36+
{
37+
nix::Tag currObj = input.entity<nix::Tag>(1);
38+
currObj.addSource(input.str(2));
39+
}
40+
2941
void retrieve_data(const extractor &input, infusor &output) {
3042
nix::Tag currObj = input.entity<nix::Tag>(1);
3143
double index = input.num<double>(2);

src/nixtag.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace nixtag {
77

88
mxArray *describe(const nix::Tag &tag);
99

10+
void add_reference(const extractor &input, infusor &output);
11+
12+
void add_source(const extractor &input, infusor &output);
13+
1014
void retrieve_data(const extractor &input, infusor &output);
1115

1216
void retrieve_feature_data(const extractor &input, infusor &output);

tests/TestSource.m

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323

2424
%% Test: Open source by ID or name
2525
function [] = test_open_source( varargin )
26-
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
27-
getBlock = test_file.openBlock(test_file.blocks{1,1}.id);
28-
getSFromB = getBlock.open_source(getBlock.sources{1,1}.id);
29-
30-
%-- TODO: comment in, when testfile with nested sources is available
31-
%getSourceByID = getSFromB.open_source(getSFromB.sources{1,1}.id);
32-
%assert(strcmp(getSourceByID.id, ''));
33-
disp('Test Source: open source by ID ... TODO (proper testfile)');
3426

35-
%getSourceByName = getSFromB.open_source(getSFromB.sources{1,1}.name);
36-
%assert(strcmp(getSourceByName.id, ''));
37-
disp('Test Source: open source by name ... TODO (proper testfile)');
38-
27+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
28+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
29+
getSource = getBlock.create_source('sourcetest','nixsource');
30+
assert(isempty(getSource.sources));
31+
32+
sourceName = 'nestedsource';
33+
createSource = getSource.create_source(sourceName, 'nixsource');
34+
getSourceByID = getSource.open_source(createSource.id);
35+
assert(~isempty(getSourceByID));
36+
37+
getSourceByName = getSource.open_source(sourceName);
38+
assert(~isempty(getSourceByName));
39+
3940
%-- test open non existing source
40-
getSource = getSFromB.open_source('I dont exist');
41-
assert(isempty(getSource));
41+
getNonSource = getSource.open_source('I dont exist');
42+
assert(isempty(getNonSource));
4243
end
4344

4445
%% Test: Open metadata

tests/TestTag.m

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
% Detailed explanation goes here
44

55
funcs = {};
6+
funcs{end+1} = @test_add_source;
7+
funcs{end+1} = @test_remove_source;
8+
funcs{end+1} = @test_add_reference;
9+
funcs{end+1} = @test_remove_reference;
610
funcs{end+1} = @test_list_fetch_references;
711
funcs{end+1} = @test_list_fetch_sources;
812
funcs{end+1} = @test_list_fetch_features;
@@ -14,6 +18,80 @@
1418
funcs{end+1} = @test_retrieve_feature_data;
1519
end
1620

21+
%% Test: Add sources by entity and id
22+
function [] = test_add_source ( varargin )
23+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
24+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
25+
getSource = getBlock.create_source('sourcetest','nixsource');
26+
createSource1 = getSource.create_source('nestedsource1','nixsource');
27+
createSource2 = getSource.create_source('nestedsource2','nixsource');
28+
position = [1.0 1.2 1.3 15.9];
29+
getTag = getBlock.create_tag('foo', 'bar', position);
30+
31+
assert(isempty(getTag.sources));
32+
getTag.add_source(getSource.sources{1}.id);
33+
getTag.add_source(getSource.sources{2});
34+
assert(size(getTag.sources,1) == 2);
35+
end
36+
37+
%% Test: Remove sources by entity and id
38+
function [] = test_remove_source ( varargin )
39+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
40+
getBlock = test_file.createBlock('sourcetest', 'nixblock');
41+
getSource = getBlock.create_source('sourcetest','nixsource');
42+
createSource1 = getSource.create_source('nestedsource1','nixsource');
43+
createSource2 = getSource.create_source('nestedsource2','nixsource');
44+
position = [1.0 1.2 1.3 15.9];
45+
getTag = getBlock.create_tag('foo', 'bar', position);
46+
getTag.add_source(getSource.sources{1}.id);
47+
getTag.add_source(getSource.sources{2});
48+
49+
assert(size(getTag.sources,1) == 2);
50+
getTag.remove_source(getSource.sources{2});
51+
assert(size(getTag.sources,1) == 1);
52+
getTag.remove_source(getSource.sources{1}.id);
53+
assert(isempty(getTag.sources));
54+
assert(getTag.remove_source('I do not exist'));
55+
assert(size(getSource.sources,1) == 2);
56+
end
57+
58+
%% Test: Add references by entity and id
59+
function [] = test_add_reference ( varargin )
60+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
61+
getBlock = test_file.createBlock('referenceTest', 'nixblock');
62+
getRefDA1 = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
63+
getRefDA2 = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
64+
65+
position = [1.0 1.2 1.3 15.9];
66+
getTag = getBlock.create_tag('referenceTest', 'nixTag', position);
67+
68+
assert(isempty(getTag.references));
69+
getTag.add_reference(getBlock.dataArrays{1}.id);
70+
getTag.add_reference(getBlock.dataArrays{2});
71+
assert(size(getTag.references, 1) == 2);
72+
end
73+
74+
%% Test: Remove references by entity and id
75+
function [] = test_remove_reference ( varargin )
76+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
77+
getBlock = test_file.createBlock('referenceTest', 'nixblock');
78+
getRefDA1 = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
79+
getRefDA2 = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
80+
81+
position = [1.0 1.2 1.3 15.9];
82+
getTag = getBlock.create_tag('referenceTest', 'nixTag', position);
83+
getTag.add_reference(getBlock.dataArrays{1}.id);
84+
getTag.add_reference(getBlock.dataArrays{2});
85+
assert(size(getTag.references, 1) == 2);
86+
87+
getTag.remove_reference(getBlock.dataArrays{2});
88+
assert(size(getTag.references, 1) == 1);
89+
getTag.remove_reference(getBlock.dataArrays{1}.id);
90+
assert(isempty(getTag.references));
91+
assert(~getTag.remove_reference('I do not exist'));
92+
assert(size(getBlock.dataArrays, 1) == 2);
93+
end
94+
1795
%% Test: List/fetch references
1896
function [] = test_list_fetch_references( varargin )
1997
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);

0 commit comments

Comments
 (0)