Skip to content

Commit d565da4

Browse files
committed
Merge pull request #70 from mpsonntag/createDelete
Refactored Feature entity handling, add positions/extents for Multitag entity
2 parents 62dfc68 + f58819c commit d565da4

16 files changed

+298
-79
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/MultiTag.m

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@
5454
% ------------------
5555
% Features methods
5656
% ------------------
57-
57+
58+
function retObj = add_feature(obj, add_this, link_type)
59+
if(strcmp(class(add_this), 'nix.DataArray'))
60+
addID = add_this.id;
61+
else
62+
addID = add_this;
63+
end;
64+
retObj = nix.Feature(nix_mx('MultiTag::createFeature', obj.nix_handle, addID, link_type));
65+
obj.featuresCache.lastUpdate = 0;
66+
end;
67+
68+
function delCheck = remove_feature(obj, del)
69+
[delCheck, obj.featuresCache] = nix.Utils.delete_entity(obj, ...
70+
del, 'nix.Feature', 'MultiTag::deleteFeature', obj.featuresCache);
71+
end;
72+
5873
function retObj = open_feature(obj, id_or_name)
5974
retObj = nix.Utils.open_entity(obj, ...
6075
'MultiTag::openFeature', id_or_name, @nix.Feature);
@@ -87,7 +102,16 @@
87102
retObj = nix.DataArray(handle);
88103
end;
89104
end;
90-
105+
106+
function [] = add_positions(obj, add_this)
107+
if(strcmp(class(add_this), 'nix.DataArray'))
108+
addID = add_this.id;
109+
else
110+
addID = add_this;
111+
end;
112+
nix_mx('MultiTag::addPositions', obj.nix_handle, addID);
113+
end;
114+
91115
% ------------------
92116
% Extents methods
93117
% ------------------
@@ -100,5 +124,14 @@
100124
end;
101125
end;
102126

127+
function [] = add_extents(obj, add_this)
128+
if(strcmp(class(add_this), 'nix.DataArray'))
129+
addID = add_this.id;
130+
else
131+
addID = add_this;
132+
end;
133+
nix_mx('MultiTag::addExtents', obj.nix_handle, addID);
134+
end;
135+
103136
end;
104137
end

+nix/Section.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
% Section methods
4848
% ----------------
4949

50+
function newSec = createSection(obj, name, type)
51+
newSec = nix.Section(nix_mx('Section::createSection', obj.nix_handle, name, type));
52+
obj.sectionsCache.lastUpdate = 0;
53+
end;
54+
55+
function delCheck = deleteSection(obj, del)
56+
delCheck = nix.Utils.delete_entity(obj, del, 'nix.Section', 'Section::deleteSection');
57+
obj.sectionsCache.lastUpdate = 0;
58+
end;
59+
5060
function retObj = open_section(obj, id_or_name)
5161
retObj = nix.Utils.open_entity(obj, ...
5262
'Section::openSection', id_or_name, @nix.Section);

nix_mx.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,15 @@ void mexFunction(int nlhs,
171171
.reg("openSource", GETBYSTR(nix::Source, nix::MultiTag, getSource))
172172
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::MultiTag, metadata))
173173
.reg("removeReference", REMOVER(nix::DataArray, nix::MultiTag, removeReference))
174-
.reg("removeSource", REMOVER(nix::Source, nix::MultiTag, removeSource));
174+
.reg("removeSource", REMOVER(nix::Source, nix::MultiTag, removeSource))
175+
.reg("deleteFeature", REMOVER(nix::Feature, nix::MultiTag, deleteFeature));
175176
methods->add("MultiTag::retrieveData", nixmultitag::retrieve_data);
176177
methods->add("MultiTag::featureRetrieveData", nixmultitag::retrieve_feature_data);
177178
methods->add("MultiTag::addReference", nixmultitag::add_reference);
178179
methods->add("MultiTag::addSource", nixmultitag::add_source);
180+
methods->add("MultiTag::createFeature", nixmultitag::create_feature);
181+
methods->add("MultiTag::addPositions", nixmultitag::add_positions);
182+
methods->add("MultiTag::addExtents", nixmultitag::add_extents);
179183

180184
classdef<nix::Section>("Section", methods)
181185
.desc(&nixsection::describe)
@@ -184,14 +188,15 @@ void mexFunction(int nlhs,
184188
.reg("hasProperty", GETBYSTR(bool, nix::Section, hasProperty))
185189
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
186190
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
187-
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent));
191+
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent))
192+
.reg("createSection", &nix::Section::createSection)
193+
.reg("deleteSection", REMOVER(nix::Section, nix::Section, deleteSection));
188194
//.reg("set_repository", SETTER(const std::string&, nix::Section, repository));
189195
methods->add("Section::properties", nixsection::properties);
190196

191197
classdef<nix::Feature>("Feature", methods)
192198
.desc(&nixfeature::describe)
193199
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
194-
methods->add("Feature::linkType", nixfeature::link_type);
195200

196201
mexAtExit(on_exit);
197202
});

src/nixfeature.cc

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

1313
mxArray *describe(const nix::Feature &feat)
1414
{
15-
struct_builder sb({ 1 }, { "id" });
15+
struct_builder sb({ 1 }, { "id", "linkType" });
1616
sb.set(feat.id());
17+
sb.set(feat.linkType());
1718
return sb.array();
1819
}
1920

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-
2921
} // 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

src/nixmultitag.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ namespace nixmultitag {
3636
currObj.addSource(input.str(2));
3737
}
3838

39+
void create_feature(const extractor &input, infusor &output)
40+
{
41+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
42+
43+
nix::Feature newFeat = currObj.createFeature(input.str(2), input.ltype(3));
44+
output.set(0, handle(newFeat));
45+
}
46+
3947
void retrieve_data(const extractor &input, infusor &output) {
4048
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
4149
double p_index = input.num<double>(2);
@@ -54,4 +62,18 @@ namespace nixmultitag {
5462
output.set(0, data);
5563
}
5664

65+
void add_positions(const extractor &input, infusor &output)
66+
{
67+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
68+
currObj.positions(input.str(2));
69+
}
70+
71+
void add_extents(const extractor &input, infusor &output)
72+
{
73+
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
74+
currObj.extents(input.str(2));
75+
}
76+
77+
void remove_extents(const extractor &input, infusor &output);
78+
5779
} // namespace nixmultitag

src/nixmultitag.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ namespace nixmultitag {
1111

1212
void add_source(const extractor &input, infusor &output);
1313

14+
void create_feature(const extractor &input, infusor &output);
15+
1416
void retrieve_data(const extractor &input, infusor &output);
1517

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

20+
void add_positions(const extractor &input, infusor &output);
21+
22+
void add_extents(const extractor &input, infusor &output);
23+
1824
} // namespace nixmultitag
1925

2026
#endif

src/nixtag.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ namespace nixtag {
4242
{
4343
nix::Tag currObj = input.entity<nix::Tag>(1);
4444

45-
uint8_t ltype = input.num<uint8_t>(3);
46-
nix::LinkType link_type;
47-
48-
switch (ltype) {
49-
case 0: link_type = nix::LinkType::Tagged; break;
50-
case 1: link_type = nix::LinkType::Untagged; break;
51-
case 2: link_type = nix::LinkType::Indexed; break;
52-
default: throw std::invalid_argument("unkown link type");
53-
}
54-
55-
nix::Feature newFeat = currObj.createFeature(input.str(2), link_type);
45+
nix::Feature newFeat = currObj.createFeature(input.str(2), input.ltype(3));
5646
output.set(0, handle(newFeat));
5747
}
5848

src/utils/arguments.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ class extractor : public argument_helper<const mxArray> {
106106
return dtype_mex2nix(array[pos]);
107107
}
108108

109+
nix::LinkType ltype(size_t pos) const
110+
{
111+
const uint8_t link_type = num<uint8_t>(pos);
112+
nix::LinkType retLinkType;
113+
114+
switch (link_type) {
115+
case 0: retLinkType = nix::LinkType::Tagged; break;
116+
case 1: retLinkType = nix::LinkType::Untagged; break;
117+
case 2: retLinkType = nix::LinkType::Indexed; break;
118+
default: throw std::invalid_argument("unkown link type");
119+
}
120+
121+
return retLinkType;
122+
}
123+
109124
bool logical(size_t pos) const {
110125
check_arg_type(pos, nix::DataType::Bool);
111126

0 commit comments

Comments
 (0)