Skip to content

Commit 2b1e18f

Browse files
committed
refactor feature entity
1 parent aefad5c commit 2b1e18f

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

+nix/Feature.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88

99
properties(Dependent)
1010
id
11+
linkType
1112
end;
1213

1314
methods
1415
function obj = Feature(h)
1516
1617
end;
17-
18+
1819
function id = get.id(obj)
1920
id = obj.info.id;
2021
end;
21-
22-
function linkType = link_type(obj)
23-
linkType = nix_mx('Feature::linkType', obj.nix_handle);
22+
23+
function linkType = get.linkType(obj)
24+
linkType = obj.info.linkType;
2425
end;
25-
26-
function dataArray = open_data(obj, id_or_name)
27-
daHandle = nix_mx('Feature::openData', obj.nix_handle, id_or_name);
28-
dataArray = nix.Feature(daHandle);
26+
27+
function dataArray = open_data(obj)
28+
dataArray = nix.DataArray(nix_mx('Feature::openData', obj.nix_handle));
2929
end;
3030
end;
3131

nix_mx.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ void mexFunction(int nlhs,
195195
classdef<nix::Feature>("Feature", methods)
196196
.desc(&nixfeature::describe)
197197
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
198-
methods->add("Feature::linkType", nixfeature::link_type);
199198

200199
mexAtExit(on_exit);
201200
});

src/nixfeature.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ namespace nixfeature {
1212

1313
mxArray *describe(const nix::Feature &feat)
1414
{
15-
struct_builder sb({ 1 }, { "id" });
15+
nix::LinkType link_type = feat.linkType();
16+
uint8_t ltype;
17+
18+
switch (link_type) {
19+
case nix::LinkType::Tagged: ltype = 0; break;
20+
case nix::LinkType::Untagged: ltype = 1; break;
21+
case nix::LinkType::Indexed: ltype = 2; break;
22+
default: throw std::invalid_argument("unkown link type");
23+
}
24+
25+
struct_builder sb({ 1 }, { "id", "linkType" });
1626
sb.set(feat.id());
27+
sb.set(ltype);
1728
return sb.array();
1829
}
1930

20-
void link_type(const extractor &input, infusor &output)
21-
{
22-
nix::Feature currFeat = input.entity<nix::Feature>(1);
23-
//TODO properly implement link type
24-
struct_builder sb({ 1 }, { "linkType" });
25-
sb.set("linkType");
26-
output.set(0, sb.array());
27-
}
28-
2931
} // namespace nixfeature

src/nixfeature.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace nixfeature {
77

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

10-
void link_type(const extractor &input, infusor &output);
11-
1210
} // namespace nixfeature
1311

1412
#endif

tests/RunTests.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
t6.tests = TestMultiTag();
2828
t7.name = 'SECTION';
2929
t7.tests = TestSection();
30-
31-
%-- TODO: TestFeature
30+
t8.name = 'FEATURE';
31+
t8.tests = TestFeature();
3232

3333
% concatenate all test handles
34-
all_tests = {t1, t2, t3, t4, t5, t6, t7};
34+
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8};
3535

3636
for i = 1:length(all_tests)
3737
fprintf([10 'Execute ' all_tests{i}.name ' tests:\n\n']);

tests/TestFeature.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function funcs = TestFeature
2+
%TESTTag tests for Tag
3+
% Detailed explanation goes here
4+
5+
funcs = {};
6+
funcs{end+1} = @test_open_data;
7+
end
8+
9+
%% Test: Open data from feature
10+
function [] = test_open_data ( varargin )
11+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
12+
b = f.createBlock('featureTest', 'nixBlock');
13+
tmp = b.create_data_array('featureTestDataArray', 'nixDataArray', 'double', [1 2 3 4 5 6]);
14+
getTag = b.create_tag('featureTest', 'nixTag', [1, 2]);
15+
tmp = getTag.add_feature(b.dataArrays{1}, nix.LinkType.Tagged);
16+
17+
getFeature = getTag.features{1};
18+
assert(~isempty(getFeature.open_data));
19+
end

0 commit comments

Comments
 (0)