Skip to content

Commit 5fce7be

Browse files
committed
add/remove source/ref from multitag
1 parent f9c2e2c commit 5fce7be

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

+nix/MultiTag.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,17 @@
7474
% ------------------
7575
% References methods
7676
% ------------------
77-
77+
78+
function [] = add_reference(obj, add_this)
79+
obj.referencesCache = nix.Utils.add_entity(obj, ...
80+
add_this, 'nix.DataArray', 'MultiTag::addReference', obj.referencesCache);
81+
end;
82+
83+
function delCheck = remove_reference(obj, del)
84+
[delCheck, obj.referencesCache] = nix.Utils.delete_entity(obj, ...
85+
del, 'nix.DataArray', 'MultiTag::removeReference', obj.referencesCache);
86+
end;
87+
7888
function retObj = open_reference(obj, id_or_name)
7989
retObj = nix.Utils.open_entity(obj, ...
8090
'MultiTag::openReferences', id_or_name, @nix.DataArray);
@@ -127,6 +137,16 @@
127137
% Sources methods
128138
% ------------------
129139

140+
function [] = add_source(obj, add_this)
141+
obj.sourcesCache = nix.Utils.add_entity(obj, ...
142+
add_this, 'nix.Source', 'MultiTag::addSource', obj.sourcesCache);
143+
end;
144+
145+
function delCheck = remove_source(obj, del)
146+
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
147+
del, 'nix.Source', 'MultiTag::removeSource', obj.sourcesCache);
148+
end;
149+
130150
function retObj = open_source(obj, id_or_name)
131151
retObj = nix.Utils.open_entity(obj, ...
132152
'MultiTag::openSource', id_or_name, @nix.Source);

nix_mx.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,13 @@ void mexFunction(int nlhs,
161161
.reg("openReferences", GETBYSTR(nix::DataArray, nix::MultiTag, getReference))
162162
.reg("openFeature", GETBYSTR(nix::Feature, nix::MultiTag, getFeature))
163163
.reg("openSource", GETBYSTR(nix::Source, nix::MultiTag, getSource))
164-
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::MultiTag, metadata));
164+
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::MultiTag, metadata))
165+
.reg("removeReference", REMOVER(nix::DataArray, nix::MultiTag, removeReference))
166+
.reg("removeSource", REMOVER(nix::Source, nix::MultiTag, removeSource));
165167
methods->add("MultiTag::retrieveData", nixmultitag::retrieve_data);
166168
methods->add("MultiTag::featureRetrieveData", nixmultitag::retrieve_feature_data);
169+
methods->add("MultiTag::addReference", nixmultitag::add_reference);
170+
methods->add("MultiTag::addSource", nixmultitag::add_source);
167171

168172
classdef<nix::Section>("Section", methods)
169173
.desc(&nixsection::describe)

src/nixmultitag.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ namespace nixmultitag {
2424
return sb.array();
2525
}
2626

27+
void add_reference(const extractor &input, infusor &output)
28+
{
29+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
30+
currObj.addReference(input.str(2));
31+
}
32+
33+
void add_source(const extractor &input, infusor &output)
34+
{
35+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
36+
currObj.addSource(input.str(2));
37+
}
38+
2739
void retrieve_data(const extractor &input, infusor &output) {
2840
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
2941
double p_index = input.num<double>(2);

src/nixmultitag.h

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

88
mxArray *describe(const nix::MultiTag &multitag);
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/TestMultiTag.m

Lines changed: 83 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;
@@ -17,6 +21,85 @@
1721
funcs{end+1} = @test_retrieve_feature_data;
1822
end
1923

24+
%% Test: Add sources by entity and id
25+
function [] = test_add_source ( varargin )
26+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
27+
getBlock = test_file.createBlock('sourceTest', 'nixBlock');
28+
getSource = getBlock.create_source('sourceTest', 'nixSource');
29+
tmp = getSource.create_source('nestedSource1', 'nixSource');
30+
tmp = getSource.create_source('nestedSource2', 'nixSource');
31+
32+
% getMTag = getBlock.create_multitag('sourcetest', 'nixMultiTag', position);
33+
34+
% assert(isempty(getMTag.sources));
35+
% getMTag.add_source(getSource.sources{1}.id);
36+
% getMTag.add_source(getSource.sources{2});
37+
% assert(size(getMTag.sources,1) == 2);
38+
disp('Test MultiTag: add sources ... TODO (create block multitag method missing)');
39+
end
40+
41+
%% Test: Remove sources by entity and id
42+
function [] = test_remove_source ( varargin )
43+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
44+
getBlock = test_file.createBlock('test', 'nixBlock');
45+
getSource = getBlock.create_source('test', 'nixSource');
46+
tmp = getSource.create_source('nestedSource1', 'nixSource');
47+
tmp = getSource.create_source('nestedSource2', 'nixSource');
48+
49+
% getMTag = getBlock.create_multitag('sourcetest', 'nixMultiTag', position);
50+
% getMTag.add_source(getSource.sources{1}.id);
51+
% getMTag.add_source(getSource.sources{2});
52+
%
53+
% assert(size(getMTag.sources,1) == 2);
54+
% getMTag.remove_source(getSource.sources{2});
55+
% assert(size(getMTag.sources,1) == 1);
56+
% getMTag.remove_source(getSource.sources{1}.id);
57+
% assert(isempty(getMTag.sources));
58+
% assert(getMTag.remove_source('I do not exist'));
59+
% assert(size(getSource.sources,1) == 2);
60+
61+
disp('Test MultiTag: remove sources ... TODO (create block multitag method missing)');
62+
end
63+
64+
%% Test: Add references by entity and id
65+
function [] = test_add_reference ( varargin )
66+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
67+
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
68+
tmp = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
69+
tmp = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
70+
71+
% getMTag = getBlock.create_multitag('referenceTest', 'nixMTag', position);
72+
%
73+
% assert(isempty(getMTag.references));
74+
% getMTag.add_reference(getBlock.dataArrays{1}.id);
75+
% getMTag.add_reference(getBlock.dataArrays{2});
76+
% assert(size(getMTag.references, 1) == 2);
77+
78+
disp('Test MultiTag: add reference ... TODO (create block multitag method missing)');
79+
end
80+
81+
%% Test: Remove references by entity and id
82+
function [] = test_remove_reference ( varargin )
83+
test_file = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
84+
getBlock = test_file.createBlock('referenceTest', 'nixBlock');
85+
tmp = getBlock.create_data_array('referenceTest1', 'nixDataArray', 'double', [1 2]);
86+
tmp = getBlock.create_data_array('referenceTest2', 'nixDataArray', 'double', [3 4]);
87+
88+
% getMTag = getBlock.create_multitag('referenceTest', 'nixMultiTag', position);
89+
% getMTag.add_reference(getBlock.dataArrays{1}.id);
90+
% getMTag.add_reference(getBlock.dataArrays{2});
91+
% assert(size(getMTag.references, 1) == 2);
92+
%
93+
% getMTag.remove_reference(getBlock.dataArrays{2});
94+
% assert(size(getMTag.references, 1) == 1);
95+
% getMTag.remove_reference(getBlock.dataArrays{1}.id);
96+
% assert(isempty(getMTag.references));
97+
% assert(~getMTag.remove_reference('I do not exist'));
98+
% assert(size(getBlock.dataArrays, 1) == 2);
99+
100+
disp('Test MultiTag: remove reference ... TODO (create block multitag method missing)');
101+
end
102+
20103
%% Test: List/fetch references
21104
function [] = test_list_fetch_references( varargin )
22105
test_file = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);

0 commit comments

Comments
 (0)