Skip to content

Commit aab09cb

Browse files
committed
Merge pull request #74 from asobolev/master
Setters for type/definition on DataArray
2 parents d5aca78 + abff6fb commit aab09cb

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

nix_mx.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ static void on_exit() {
5555
}
5656

5757
#define GETTER(type, class, name) static_cast<type(class::*)()const>(&class::name)
58+
#define FILTER(type, class, filt, name) static_cast<type(class::*)(filt)const>(&class::name)
5859
#define SETTER(type, class, name) static_cast<void(class::*)(type)>(&class::name)
60+
#define REMOVER(type, class, name) static_cast<bool(class::*)(const std::string&)>(&class::name)
5961
#define GETBYSTR(type, class, name) static_cast<type(class::*)(const std::string &)const>(&class::name)
6062
#define GETCONTENT(type, class, name) static_cast<type(class::*)()const>(&class::name)
61-
#define GETSOURCES(base__) static_cast<std::vector<nix::Source>(nix::base::EntityWithSources<nix::base::base__>::*)(std::function<bool(const nix::Source &)>)const>(&nix::base::EntityWithSources<nix::base::base__>::sources)
62-
//required to open nix::Section from DataArray, normal GETCONTENT leads to a compiler error with Visual Studio 12
63-
#define GETMETADATA(base__) static_cast<nix::Section(nix::base::EntityWithMetadata<nix::base::base__>::*)()const>(&nix::base::EntityWithMetadata<nix::base::base__>::metadata)
64-
#define REMOVER(type, class, name) static_cast<bool(class::*)(const std::string&)>(&class::name)
63+
64+
//required to operate on DataArray, Visual Studio 12 compiler does not resolve multiple inheritance properly
65+
#define IDATAARRAY(type, iface, attr, name, isconst) static_cast<type(nix::base::iface<nix::base::IDataArray>::*)(attr)isconst>(&nix::base::iface<nix::base::IDataArray>::name)
66+
6567

6668
// main entry point
6769
void mexFunction(int nlhs,
@@ -127,12 +129,11 @@ void mexFunction(int nlhs,
127129

128130
classdef<nix::DataArray>("DataArray", methods)
129131
.desc(&nixdataarray::describe)
130-
.reg("sources", GETSOURCES(IDataArray))
131-
.reg("openMetadataSection", GETMETADATA(IDataArray))
132-
// the following setter lead to an error
133-
//.reg("set_type", SETTER(const std::string&, nix::DataArray, type))
134-
//.reg("set_definition", SETTER(const std::string&, nix::DataArray, definition))
135-
//.reg("set_none_definition", SETTER(const boost::none_t, nix::DataArray, definition))
132+
.reg("sources", IDATAARRAY(std::vector<nix::Source>, EntityWithSources, std::function<bool(const nix::Source &)>, sources, const))
133+
.reg("openMetadataSection", IDATAARRAY(nix::Section, EntityWithMetadata, , metadata, const))
134+
.reg("set_type", IDATAARRAY(void, NamedEntity, const std::string&, type,))
135+
.reg("set_definition", IDATAARRAY(void, NamedEntity, const std::string&, definition, ))
136+
.reg("set_none_definition", IDATAARRAY(void, NamedEntity, const boost::none_t, definition, ))
136137
.reg("set_label", SETTER(const std::string&, nix::DataArray, label))
137138
.reg("set_none_label", SETTER(const boost::none_t, nix::DataArray, label))
138139
.reg("set_unit", SETTER(const std::string&, nix::DataArray, unit))
@@ -158,7 +159,7 @@ void mexFunction(int nlhs,
158159
.desc(&nixtag::describe)
159160
.reg("references", GETTER(std::vector<nix::DataArray>, nix::Tag, references))
160161
.reg("features", &nix::Tag::features)
161-
.reg("sources", GETSOURCES(ITag))
162+
.reg("sources", FILTER(std::vector<nix::Source>, nix::Tag, std::function<bool(const nix::Source &)>, sources))
162163
.reg("openReferenceDataArray", GETBYSTR(nix::DataArray, nix::Tag, getReference))
163164
.reg("openFeature", GETBYSTR(nix::Feature, nix::Tag, getFeature))
164165
.reg("openSource", GETBYSTR(nix::Source, nix::Tag, getSource))
@@ -176,7 +177,7 @@ void mexFunction(int nlhs,
176177
.desc(&nixmultitag::describe)
177178
.reg("references", GETTER(std::vector<nix::DataArray>, nix::MultiTag, references))
178179
.reg("features", &nix::MultiTag::features)
179-
.reg("sources", GETSOURCES(IMultiTag))
180+
.reg("sources", FILTER(std::vector<nix::Source>, nix::MultiTag, std::function<bool(const nix::Source &)>, sources))
180181
.reg("hasPositions", GETCONTENT(bool, nix::MultiTag, hasPositions))
181182
.reg("openPositions", GETCONTENT(nix::DataArray, nix::MultiTag, positions))
182183
.reg("openExtents", GETCONTENT(nix::DataArray, nix::MultiTag, extents))

tests/TestDataArray.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
assert(strcmp(da.type, 'test nixDataArray'));
2424

2525
%-- TODO does not work at the moment on the c++ side
26-
%da.type = 'nixDataArray';
27-
%assert(strcmp(da.type, 'nixDataArray'));
26+
da.type = 'nixDataArray';
27+
assert(strcmp(da.type, 'nixDataArray'));
2828

29-
%assert(isempty(da.definition));
30-
%b.definition = 'data array definition';
31-
%assert(strcmp(da.definition, 'data array definition'));
29+
assert(isempty(da.definition));
30+
da.definition = 'data array definition';
31+
assert(strcmp(da.definition, 'data array definition'));
3232

33-
%da.definition = '';
34-
%assert(isempty(da.definition));
33+
da.definition = '';
34+
assert(isempty(da.definition));
3535

3636
assert(isempty(da.unit));
3737
da.unit = 'ms';

0 commit comments

Comments
 (0)