Skip to content

Commit 76adb66

Browse files
committed
Merge pull request #59 from mpsonntag/refGlueMethods
Fendpoint to glue method mapping
2 parents 9652a09 + 8f92ec9 commit 76adb66

17 files changed

+58
-131
lines changed

nix_mx.cc

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,6 @@ static void entity_updated_at(const extractor &input, infusor &output)
4242

4343
// *** ***
4444

45-
typedef void(*fn_t)(const extractor &input, infusor &output);
46-
47-
struct fendpoint {
48-
49-
fendpoint(std::string name, fn_t fn) : name(name), fn(fn) {}
50-
51-
std::string name;
52-
fn_t fn;
53-
};
54-
55-
const std::vector<fendpoint> funcs = {
56-
// File
57-
{ "File::createBlock", nixfile::create_block },
58-
{ "File::createSection", nixfile::create_section },
59-
60-
// Block
61-
{ "Block::describe", nixblock::describe },
62-
63-
// Data Array
64-
{ "DataArray::describe", nixdataarray::describe },
65-
{ "DataArray::readAll", nixdataarray::read_all },
66-
67-
// Tag
68-
{ "Tag::describe", nixtag::describe },
69-
{ "Tag::retrieveData", nixtag::retrieve_data },
70-
{ "Tag::featureRetrieveData", nixtag::retrieve_feature_data },
71-
72-
// Multi Tag
73-
{ "MultiTag::describe", nixmultitag::describe },
74-
{ "MultiTag::retrieveData", nixmultitag::retrieve_data },
75-
{ "MultiTag::featureRetrieveData", nixmultitag::retrieve_feature_data },
76-
77-
// Source
78-
{ "Source::describe", nixsource::describe },
79-
80-
// Feature
81-
{ "Feature::describe", nixfeature::describe },
82-
{ "Feature::linkType", nixfeature::link_type },
83-
84-
// Section
85-
{ "Section::describe", nixsection::describe },
86-
{ "Section::properties", nixsection::properties }
87-
};
88-
8945
//glue "globals"
9046
std::once_flag init_flag;
9147
static glue::registry *methods = nullptr;
@@ -139,9 +95,12 @@ void mexFunction(int nlhs,
13995
.reg("deleteBlock", REMOVER(nix::Block, nix::File, deleteBlock))
14096
.reg("deleteSection", REMOVER(nix::Section, nix::File, deleteSection))
14197
.reg("openBlock", GETBYSTR(nix::Block, nix::File, getBlock))
142-
.reg("openSection", GETBYSTR(nix::Section, nix::File, getSection));
98+
.reg("openSection", GETBYSTR(nix::Section, nix::File, getSection))
99+
.reg("createBlock", &nix::File::createBlock)
100+
.reg("createSection", &nix::File::createSection);
143101

144102
classdef<nix::Block>("Block", methods)
103+
.desc(&nixblock::describe)
145104
.reg("dataArrays", &nix::Block::dataArrays)
146105
.reg("createSource", &nix::Block::createSource)
147106
//.reg("createDataArray", static_cast<nix::DataArray(nix::Block::*)(const std::string &, const std::string &, nix::DataType, const nix::NDSize &)>(&nix::Block::createDataArray))
@@ -160,25 +119,32 @@ void mexFunction(int nlhs,
160119
methods->add("Block::createDataArray", nixblock::create_data_array);
161120

162121
classdef<nix::DataArray>("DataArray", methods)
122+
.desc(&nixdataarray::describe)
163123
.reg("sources", GETSOURCES(IDataArray))
164124
.reg("openMetadataSection", GETMETADATA(IDataArray));
125+
methods->add("DataArray::readAll", nixdataarray::read_all);
165126
methods->add("DataArray::writeAll", nixdataarray::write_all);
166127

167128
classdef<nix::Source>("Source", methods)
129+
.desc(&nixsource::describe)
168130
.reg("sources", &nix::Source::sources)
169131
.reg("openSource", GETBYSTR(nix::Source, nix::Source, getSource))
170132
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Source, metadata));
171133

172134
classdef<nix::Tag>("Tag", methods)
135+
.desc(&nixtag::describe)
173136
.reg("references", GETTER(std::vector<nix::DataArray>, nix::Tag, references))
174137
.reg("features", &nix::Tag::features)
175138
.reg("sources", GETSOURCES(ITag))
176139
.reg("openReferenceDataArray", GETBYSTR(nix::DataArray, nix::Tag, getReference))
177140
.reg("openFeature", GETBYSTR(nix::Feature, nix::Tag, getFeature))
178141
.reg("openSource", GETBYSTR(nix::Source, nix::Tag, getSource))
179142
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::Tag, metadata));
143+
methods->add("Tag::retrieveData", nixtag::retrieve_data);
144+
methods->add("Tag::featureRetrieveData", nixtag::retrieve_feature_data);
180145

181146
classdef<nix::MultiTag>("MultiTag", methods)
147+
.desc(&nixmultitag::describe)
182148
.reg("references", GETTER(std::vector<nix::DataArray>, nix::MultiTag, references))
183149
.reg("features", &nix::MultiTag::features)
184150
.reg("sources", GETSOURCES(IMultiTag))
@@ -189,17 +155,23 @@ void mexFunction(int nlhs,
189155
.reg("openFeature", GETBYSTR(nix::Feature, nix::MultiTag, getFeature))
190156
.reg("openSource", GETBYSTR(nix::Source, nix::MultiTag, getSource))
191157
.reg("openMetadataSection", GETCONTENT(nix::Section, nix::MultiTag, metadata));
158+
methods->add("MultiTag::retrieveData", nixmultitag::retrieve_data);
159+
methods->add("MultiTag::featureRetrieveData", nixmultitag::retrieve_feature_data);
192160

193161
classdef<nix::Section>("Section", methods)
162+
.desc(&nixsection::describe)
194163
.reg("sections", &nix::Section::sections)
195164
.reg("openSection", GETBYSTR(nix::Section, nix::Section, getSection))
196165
.reg("hasProperty", GETBYSTR(bool, nix::Section, hasProperty))
197166
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
198167
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
199168
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent));
169+
methods->add("Section::properties", nixsection::properties);
200170

201171
classdef<nix::Feature>("Feature", methods)
172+
.desc(&nixfeature::describe)
202173
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
174+
methods->add("Feature::linkType", nixfeature::link_type);
203175

204176
mexAtExit(on_exit);
205177
});
@@ -215,18 +187,6 @@ void mexFunction(int nlhs,
215187
}
216188
#endif
217189

218-
for (const auto &fn : funcs) {
219-
220-
if (processed) {
221-
break;
222-
}
223-
224-
if (fn.name == cmd) {
225-
fn.fn(input, output);
226-
processed = true;
227-
}
228-
}
229-
230190
}
231191
catch (const std::invalid_argument &e) {
232192
mexErrMsgIdAndTxt("nix:arg:inval", e.what());

src/nixblock.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010

1111
namespace nixblock {
1212

13-
void describe(const extractor &input, infusor &output)
13+
mxArray *describe(const nix::Block &block)
1414
{
15-
nix::Block block = input.entity<nix::Block>(1);
16-
1715
struct_builder sb({ 1 }, { "id", "type", "name", "definition" });
1816

1917
sb.set(block.id());
2018
sb.set(block.type());
2119
sb.set(block.name());
2220
sb.set(block.definition());
2321

24-
output.set(0, sb.array());
22+
return sb.array();
2523
}
2624

2725
void create_data_array(const extractor &input, infusor &output)

src/nixblock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace nixblock {
77

8-
void describe(const extractor &input, infusor &output);
8+
mxArray *describe(const nix::Block &block);
99

1010
void create_data_array(const extractor &input, infusor &output);
1111

src/nixdataarray.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
namespace nixdataarray {
1414

15-
void describe(const extractor &input, infusor &output)
15+
mxArray *describe(const nix::DataArray &da)
1616
{
17-
nix::DataArray da = input.entity<nix::DataArray>(1);
18-
1917
struct_builder sb({ 1 }, { "id", "type", "name", "definition", "label",
2018
"shape", "unit", "dimensions", "polynom_coefficients" });
2119

@@ -53,7 +51,7 @@ namespace nixdataarray {
5351
sb.set(dims);
5452
sb.set(da.polynomCoefficients());
5553

56-
output.set(0, sb.array());
54+
return sb.array();
5755
}
5856

5957
void read_all(const extractor &input, infusor &output)

src/nixdataarray.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
namespace nixdataarray {
77

8-
void describe(const extractor &input, infusor &output);
9-
8+
mxArray *describe(const nix::DataArray &da);
9+
1010
void read_all(const extractor &input, infusor &output);
1111

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

src/nixfeature.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
namespace nixfeature {
1212

13-
void describe(const extractor &input, infusor &output)
13+
mxArray *describe(const nix::Feature &feat)
1414
{
15-
nix::Feature currFeat = input.entity<nix::Feature>(1);
1615
struct_builder sb({ 1 }, { "id" });
17-
sb.set(currFeat.id());
18-
output.set(0, sb.array());
16+
sb.set(feat.id());
17+
return sb.array();
1918
}
2019

2120
void link_type(const extractor &input, infusor &output)

src/nixfeature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace nixfeature {
77

8-
void describe(const extractor &input, infusor &output);
8+
mxArray *describe(const nix::Feature &feat);
99

1010
void link_type(const extractor &input, infusor &output);
1111

src/nixfile.cc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,4 @@ mxArray *describe(const nix::File &fd) {
3939
return sb.array();
4040
}
4141

42-
void create_block(const extractor &input, infusor &output)
43-
{
44-
nix::File currObj = input.entity<nix::File>(1);
45-
nix::Block newBlock = currObj.createBlock(input.str(2), input.str(3));
46-
47-
handle nbh = handle(newBlock);
48-
output.set(0, nbh);
49-
}
50-
51-
void create_section(const extractor &input, infusor &output)
52-
{
53-
nix::File currObj = input.entity<nix::File>(1);
54-
nix::Section newSection = currObj.createSection(input.str(2), input.str(3));
55-
56-
handle nsh = handle(newSection);
57-
output.set(0, nsh);
58-
}
59-
6042
} // namespace nixfile

src/nixfile.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ void open(const extractor &input, infusor &output);
99

1010
mxArray *describe(const nix::File &f);
1111

12-
void create_block(const extractor &input, infusor &output);
13-
14-
void create_section(const extractor &input, infusor &output);
15-
1612
} // namespace nixfile
1713

1814
#endif

src/nixmultitag.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
namespace nixmultitag {
1313

14-
void describe(const extractor &input, infusor &output)
14+
mxArray *describe(const nix::MultiTag &multitag)
1515
{
16-
nix::MultiTag currObj = input.entity<nix::MultiTag>(1);
17-
1816
struct_builder sb({ 1 }, { "id", "type", "name", "definition", "units" });
19-
sb.set(currObj.id());
20-
sb.set(currObj.type());
21-
sb.set(currObj.name());
22-
sb.set(currObj.definition());
23-
sb.set(currObj.units());
2417

25-
output.set(0, sb.array());
18+
sb.set(multitag.id());
19+
sb.set(multitag.type());
20+
sb.set(multitag.name());
21+
sb.set(multitag.definition());
22+
sb.set(multitag.units());
23+
24+
return sb.array();
2625
}
2726

2827
void retrieve_data(const extractor &input, infusor &output) {

0 commit comments

Comments
 (0)