Skip to content

Commit c98c3d7

Browse files
committed
added none_t to GLUE + repository / mapping setters for section
1 parent 5ba6cf0 commit c98c3d7

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

+nix/Dynamic.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ function set_method(obj, val)
2323
throwAsCaller(ME);
2424
end
2525

26-
% TODO set appropriate method name template
27-
nix_mx(strcat(obj.alias, '::set_', prop), obj.nix_handle);
26+
if (isempty(val))
27+
nix_mx(strcat(obj.alias, '::set_none_', prop), obj.nix_handle, val);
28+
else
29+
nix_mx(strcat(obj.alias, '::set_', prop), obj.nix_handle, val);
30+
end
2831
obj.info = nix_mx(strcat(obj.alias, '::describe'), obj.nix_handle);
2932
end
3033

nix_mx.cc

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

5757
#define GETTER(type, class, name) static_cast<type(class::*)()const>(&class::name)
58-
//#define SETTER(type, class, name) static_cast<void(class::*)(type)>(&class::name)
58+
#define SETTER(type, class, name) static_cast<void(class::*)(type)>(&class::name)
5959
#define GETBYSTR(type, class, name) static_cast<type(class::*)(const std::string &)const>(&class::name)
6060
#define GETCONTENT(type, class, name) static_cast<type(class::*)()const>(&class::name)
6161
#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)
@@ -184,8 +184,11 @@ void mexFunction(int nlhs,
184184
.reg("hasProperty", GETBYSTR(bool, nix::Section, hasProperty))
185185
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
186186
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
187-
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent));
188-
//.reg("set_repository", SETTER(const std::string&, nix::Section, repository));
187+
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent))
188+
.reg("set_repository", SETTER(const std::string&, nix::Section, repository))
189+
.reg("set_none_repository", SETTER(const boost::none_t, nix::Section, repository))
190+
.reg("set_mapping", SETTER(const std::string&, nix::Section, mapping))
191+
.reg("set_none_mapping", SETTER(const boost::none_t, nix::Section, mapping));
189192
methods->add("Section::properties", nixsection::properties);
190193

191194
classdef<nix::Feature>("Feature", methods)

src/nixsection.cc

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

1212
namespace nixsection {
1313

14-
mxArray *describe(const nix::Section &section)
14+
mxArray *describe(const nix::Section &section)
1515
{
1616
struct_builder sb({ 1 }, {
1717
"name", "id", "type", "repository", "mapping"

src/utils/glue.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ struct ex_getter < std::string > {
3737
}
3838
};
3939

40+
template<>
41+
struct ex_getter < boost::none_t > {
42+
static boost::none_t get(const extractor &input, int pos) {
43+
boost::none_t t = nullptr;
44+
return t;
45+
}
46+
};
47+
4048
template<typename Klazz>
4149
struct ex_getter < std::function<bool(const Klazz&)> > {
4250
static std::function<bool(const Klazz &)> get(const extractor &input, int pos) {

src/utils/mkarray.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ inline mxArray* make_mx_array(const std::vector<nix::Value> &v) {
6969
template<typename T>
7070
mxArray* make_mx_array(const boost::optional<T> &opt) {
7171
if (opt) {
72-
make_mx_array(*opt);
72+
return make_mx_array(*opt);
7373
}
74-
75-
return nullptr;
74+
else {
75+
return nullptr;
76+
}
7677
}
7778

7879
template<typename T>

tests/TestSection.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@
6060

6161
function [] = test_attrs( varargin )
6262
%% Test: Access Attributes / Links
63+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
64+
s1 = f.createSection('foo', 'bar');
65+
66+
assert(strcmp(s1.name, 'foo'));
67+
assert(strcmp(s1.type, 'bar'));
68+
assert(isempty(s1.repository));
69+
assert(isempty(s1.mapping));
70+
71+
s1.repository = 'rep1';
72+
s1.mapping = 'map1';
73+
assert(strcmp(s1.repository, 'rep1'));
74+
assert(strcmp(s1.mapping, 'map1'));
75+
76+
s1.repository = '';
77+
s1.mapping = '';
78+
assert(isempty(s1.repository));
79+
assert(isempty(s1.mapping));
80+
81+
assert(isempty(s1.link));
82+
83+
% TODO rewrite tests for link / parent
84+
6385
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
6486
s1 = f.sections{3};
6587

0 commit comments

Comments
 (0)