Skip to content

Commit 90cab60

Browse files
committed
set/delete property attributes
1 parent b8fea64 commit 90cab60

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

+nix/Property.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
% assign dynamic properties
1515
nix.Dynamic.add_dyn_attr(obj, 'unit', 'rw');
1616
nix.Dynamic.add_dyn_attr(obj, 'mapping', 'rw');
17+
nix.Dynamic.add_dyn_attr(obj, 'datatype', 'r');
1718
end;
1819
end
1920

nix_mx.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,13 @@ void mexFunction(int nlhs,
241241
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
242242

243243
classdef<nix::Property>("Property", methods)
244-
.desc(&nixproperty::describe);
244+
.desc(&nixproperty::describe)
245+
.reg("set_definition", SETTER(const std::string&, nix::Property, definition))
246+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Property, definition))
247+
.reg("set_unit", SETTER(const std::string&, nix::Property, unit))
248+
.reg("set_none_unit", SETTER(const boost::none_t, nix::Property, unit))
249+
.reg("set_mapping", SETTER(const std::string&, nix::Property, mapping))
250+
.reg("set_none_mapping", SETTER(const boost::none_t, nix::Property, mapping));
245251

246252
mexAtExit(on_exit);
247253
});

src/nixproperty.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ namespace nixproperty {
1212

1313
mxArray *describe(const nix::Property &prop)
1414
{
15-
struct_builder sb({ 1 }, { "id", "name", "definition", "unit", "mapping" });
15+
struct_builder sb({ 1 }, { "id", "name", "definition", "unit", "mapping", "datatype" });
16+
1617
sb.set(prop.id());
1718
sb.set(prop.name());
1819
sb.set(prop.definition());
1920
sb.set(prop.unit());
2021
sb.set(prop.mapping());
22+
sb.set(nix::data_type_to_string(prop.dataType()));
23+
2124
return sb.array();
2225
}
2326

tests/TestProperty.m

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@
88

99
%% Test: Access Attributes
1010
function [] = test_attrs( varargin )
11-
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
12-
s = f.sections{2}.sections{2}.sections{1};
13-
p = s.open_property(s.allProperties{1}.id);
11+
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
12+
s = f.createSection('testSectionProperty', 'nixSection');
13+
p = s.create_property_data_type('testProperty1', nix.DataType.String);
1414

1515
assert(~isempty(p.id));
16+
assert(strcmpi(p.datatype, 'string'));
17+
assert(strcmp(p.name, 'testProperty1'));
1618

17-
assert(strcmp(p.name, 'ExperimentalCondition'));
19+
assert(isempty(p.definition));
20+
assert(isempty(p.unit));
21+
assert(isempty(s.mapping));
22+
23+
p.definition = 'property definition';
24+
p.unit = 'ms';
25+
p.mapping = 'property mapping';
26+
assert(strcmp(p.definition, 'property definition'));
27+
assert(strcmp(p.unit, 'ms'));
28+
assert(strcmp(p.mapping, 'property mapping'));
29+
30+
p.definition = 'next property definition';
31+
p.unit = 'mm';
32+
p.mapping = 'next property mapping';
33+
34+
p.definition = '';
35+
p.unit = '';
36+
p.mapping = '';
1837
assert(isempty(p.definition));
1938
assert(isempty(p.unit));
2039
assert(isempty(s.mapping));

0 commit comments

Comments
 (0)