Skip to content

Commit 5479080

Browse files
committed
completify: add missing Feature functions and tests
1 parent e6ba10c commit 5479080

File tree

5 files changed

+96
-6
lines changed

5 files changed

+96
-6
lines changed

+nix/Feature.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@
2121
end;
2222

2323
function linkType = get.linkType(obj)
24-
linkType = obj.info.linkType;
24+
linkType = nix_mx('Feature::getLinkType', obj.nix_handle);
25+
end;
26+
27+
function [] = set.linkType(obj, linkType)
28+
nix_mx('Feature::setLinkType', obj.nix_handle, linkType);
2529
end;
2630

2731
function dataArray = open_data(obj)
2832
dataArray = nix.DataArray(nix_mx('Feature::openData', obj.nix_handle));
2933
end;
34+
35+
function [] = set_data(obj, setData)
36+
if(strcmp(class(setData), 'nix.DataArray'))
37+
setData = setData.id;
38+
end;
39+
nix_mx('Feature::setData', obj.nix_handle, setData);
40+
end;
3041
end;
3142

32-
end
43+
end

nix_mx.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ void mexFunction(int nlhs,
290290

291291
classdef<nix::Feature>("Feature", methods)
292292
.desc(&nixfeature::describe)
293-
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
293+
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data))
294+
.reg("setData", SETTER(const std::string&, nix::Feature, data))
295+
.reg("getLinkType", GETCONTENT(nix::LinkType, nix::Feature, linkType));
296+
methods->add("Feature::setLinkType", nixfeature::set_link_type);
294297

295298
classdef<nix::Property>("Property", methods)
296299
.desc(&nixproperty::describe)
@@ -361,4 +364,3 @@ void mexFunction(int nlhs,
361364
mexErrMsgIdAndTxt("nix:arg:dispatch", "Unkown command");
362365
}
363366
}
364-

src/nixfeature.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ namespace nixfeature {
1818
return sb.array();
1919
}
2020

21-
} // namespace nixfeature
21+
void set_link_type(const extractor &input, infusor &output)
22+
{
23+
nix::Feature feat = input.entity<nix::Feature>(1);
24+
25+
feat.linkType(input.ltype(2));
26+
}
27+
28+
} // namespace nixfeature

src/nixfeature.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace nixfeature {
77

88
mxArray *describe(const nix::Feature &feat);
99

10+
void set_link_type(const extractor &input, infusor &output);
11+
1012
} // namespace nixfeature
1113

12-
#endif
14+
#endif

tests/TestFeature.m

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
funcs = {};
66
funcs{end+1} = @test_open_data;
7+
funcs{end+1} = @test_get_set_link_type;
8+
funcs{end+1} = @test_set_data;
79
end
810

911
%% Test: Open data from feature
@@ -17,3 +19,69 @@
1719
getFeature = getTag.features{1};
1820
assert(~isempty(getFeature.open_data));
1921
end
22+
23+
%% Test: Get and set nix.LinkType
24+
function [] = test_get_set_link_type ( varargin )
25+
fileName = 'testRW.h5';
26+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
27+
b = f.createBlock('featureTest', 'nixBlock');
28+
da = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
29+
t = b.create_tag('featureTest', 'nixTag', [1, 2]);
30+
feat = t.add_feature(b.dataArrays{1}, nix.LinkType.Tagged);
31+
32+
try
33+
feat.linkType = '';
34+
catch ME
35+
assert(strcmp(ME.identifier, 'nix:arg:inval'));
36+
end;
37+
try
38+
feat.linkType = {};
39+
catch ME
40+
assert(strcmp(ME.identifier, 'nix:arg:inval'));
41+
end;
42+
try
43+
feat.linkType = 1;
44+
catch ME
45+
assert(strcmp(ME.identifier, 'nix:arg:inval'));
46+
end;
47+
assert(f.blocks{1}.tags{1}.features{1}.linkType == 0);
48+
49+
feat.linkType = nix.LinkType.Untagged;
50+
assert(f.blocks{1}.tags{1}.features{1}.linkType == 1);
51+
52+
feat.linkType = nix.LinkType.Indexed;
53+
54+
clear feat t da b f;
55+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
56+
assert(f.blocks{1}.tags{1}.features{1}.linkType == 2);
57+
end
58+
59+
%% Test: Set data by entity, ID and name
60+
function [] = test_set_data ( varargin )
61+
fileName = 'testRW.h5';
62+
daName1 = 'featTestDA1';
63+
daName2 = 'featTestDA2';
64+
daName3 = 'featTestDA3';
65+
daName4 = 'featTestDA4';
66+
daType = 'nixDataArray';
67+
daData = [1 2 3 4 5 6];
68+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.Overwrite);
69+
b = f.createBlock('featureTest', 'nixBlock');
70+
da1 = b.create_data_array(daName1, daType, 'double', daData);
71+
da2 = b.create_data_array(daName2, daType, 'double', daData);
72+
da3 = b.create_data_array(daName3, daType, 'double', daData);
73+
da4 = b.create_data_array(daName4, daType, 'double', daData);
74+
t = b.create_tag('featureTest', 'nixTag', [1, 2]);
75+
feat = t.add_feature(b.dataArrays{1}, nix.LinkType.Tagged);
76+
77+
assert(strcmp(feat.open_data.name, daName1));
78+
feat.set_data(da2);
79+
assert(strcmp(f.blocks{1}.tags{1}.features{1}.open_data.name, daName2));
80+
feat.set_data(da3.id);
81+
assert(strcmp(f.blocks{1}.tags{1}.features{1}.open_data.name, daName3));
82+
feat.set_data(da4.name);
83+
84+
clear feat t da4 da3 da2 da1 b f;
85+
f = nix.File(fullfile(pwd, 'tests', fileName), nix.FileMode.ReadOnly);
86+
assert(strcmp(f.blocks{1}.tags{1}.features{1}.open_data.name, daName4));
87+
end

0 commit comments

Comments
 (0)