Skip to content

Commit d89c722

Browse files
committed
Merge pull request #71 from asobolev/master
added none_t to GLUE + repository & mapping setters for section
2 parents d565da4 + 6df7503 commit d89c722

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
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: 5 additions & 2 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)
@@ -189,9 +189,12 @@ void mexFunction(int nlhs,
189189
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
190190
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
191191
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent))
192+
.reg("set_repository", SETTER(const std::string&, nix::Section, repository))
193+
.reg("set_none_repository", SETTER(const boost::none_t, nix::Section, repository))
194+
.reg("set_mapping", SETTER(const std::string&, nix::Section, mapping))
195+
.reg("set_none_mapping", SETTER(const boost::none_t, nix::Section, mapping))
192196
.reg("createSection", &nix::Section::createSection)
193197
.reg("deleteSection", REMOVER(nix::Section, nix::Section, deleteSection));
194-
//.reg("set_repository", SETTER(const std::string&, nix::Section, repository));
195198
methods->add("Section::properties", nixsection::properties);
196199

197200
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ inline mxArray* make_mx_array(const std::vector<nix::Value> &v) {
7070

7171
template<typename T>
7272
mxArray* make_mx_array(const boost::optional<T> &opt) {
73-
if (opt) {
74-
make_mx_array(*opt);
75-
}
76-
77-
return nullptr;
73+
if (opt) {
74+
return make_mx_array(*opt);
75+
}
76+
else {
77+
return nullptr;
78+
}
7879
}
7980

8081
template<typename T>

tests/TestSection.m

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

8989
function [] = test_attrs( varargin )
9090
%% Test: Access Attributes / Links
91+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
92+
s1 = f.createSection('foo', 'bar');
93+
94+
assert(strcmp(s1.name, 'foo'));
95+
assert(strcmp(s1.type, 'bar'));
96+
assert(isempty(s1.repository));
97+
assert(isempty(s1.mapping));
98+
99+
s1.repository = 'rep1';
100+
s1.mapping = 'map1';
101+
assert(strcmp(s1.repository, 'rep1'));
102+
assert(strcmp(s1.mapping, 'map1'));
103+
104+
s1.repository = '';
105+
s1.mapping = '';
106+
assert(isempty(s1.repository));
107+
assert(isempty(s1.mapping));
108+
109+
assert(isempty(s1.link));
110+
111+
% TODO rewrite tests for link / parent
112+
91113
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
92114
s1 = f.sections{3};
93115

0 commit comments

Comments
 (0)