Skip to content

Commit 25b5bea

Browse files
committed
add Property entity
1 parent eb5b9a4 commit 25b5bea

File tree

9 files changed

+109
-3
lines changed

9 files changed

+109
-3
lines changed

+nix/Property.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
classdef Property < nix.NamedEntity
2+
%PROPERTY Metadata Property class
3+
% NIX metadata property
4+
5+
properties(Hidden)
6+
% namespace reference for nix-mx functions
7+
alias = 'Property'
8+
end;
9+
10+
methods
11+
function obj = Property(h)
12+
13+
14+
% assign dynamic properties
15+
nix.Dynamic.add_dyn_attr(obj, 'unit', 'rw');
16+
nix.Dynamic.add_dyn_attr(obj, 'mapping', 'rw');
17+
end;
18+
end
19+
20+
end
21+

+nix/Section.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@
8686
% ----------------
8787
% Property methods
8888
% ----------------
89-
89+
90+
function retObj = open_property(obj, id_or_name)
91+
retObj = nix.Utils.open_entity(obj, ...
92+
'Section::openProperty', id_or_name, @nix.Property);
93+
end;
94+
9095
function props = get.allProperties(obj)
9196
[obj.propsCache, props] = nix.Utils.fetchPropList(obj.updatedAt, ...
9297
'Section::properties', obj.nix_handle, obj.propsCache);

nix_mx.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "nixfile.h"
1515
#include "nixsection.h"
16+
#include "nixproperty.h"
1617
#include "nixblock.h"
1718
#include "nixdataarray.h"
1819
#include "nixsource.h"
@@ -224,13 +225,17 @@ void mexFunction(int nlhs,
224225
.reg("set_mapping", SETTER(const std::string&, nix::Section, mapping))
225226
.reg("set_none_mapping", SETTER(const boost::none_t, nix::Section, mapping))
226227
.reg("createSection", &nix::Section::createSection)
227-
.reg("deleteSection", REMOVER(nix::Section, nix::Section, deleteSection));
228+
.reg("deleteSection", REMOVER(nix::Section, nix::Section, deleteSection))
229+
.reg("openProperty", GETBYSTR(nix::Property, nix::Section, getProperty));
228230
methods->add("Section::properties", nixsection::properties);
229231

230232
classdef<nix::Feature>("Feature", methods)
231233
.desc(&nixfeature::describe)
232234
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
233235

236+
classdef<nix::Property>("Property", methods)
237+
.desc(&nixproperty::describe);
238+
234239
mexAtExit(on_exit);
235240
});
236241

src/nixproperty.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "nixproperty.h"
2+
3+
#include "mex.h"
4+
5+
#include <nix.hpp>
6+
7+
#include "handle.h"
8+
#include "arguments.h"
9+
#include "struct.h"
10+
11+
namespace nixproperty {
12+
13+
mxArray *describe(const nix::Property &prop)
14+
{
15+
struct_builder sb({ 1 }, { "id", "name", "definition", "unit", "mapping" });
16+
sb.set(prop.id());
17+
sb.set(prop.name());
18+
sb.set(prop.definition());
19+
sb.set(prop.unit());
20+
sb.set(prop.mapping());
21+
return sb.array();
22+
}
23+
24+
} // namespace nixproperty

src/nixproperty.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef NIX_MX_PROPERTY
2+
#define NIX_MX_PROPERTY
3+
4+
#include "arguments.h"
5+
6+
namespace nixproperty {
7+
8+
mxArray *describe(const nix::Property &prop);
9+
10+
} // namespace nixproperty
11+
12+
#endif

src/utils/handle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ struct entity_to_id<nix::Section> {
5757
static const int value = 7;
5858
};
5959

60+
template<>
61+
struct entity_to_id<nix::Property> {
62+
static const bool is_valid = true;
63+
static const int value = 8;
64+
};
65+
6066
class handle {
6167
public:
6268
struct entity {

tests/RunTests.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@
2929
t7.tests = TestSection();
3030
t8.name = 'FEATURE';
3131
t8.tests = TestFeature();
32+
t9.name = 'PROPERTY';
33+
t9.tests = TestProperty();
3234

3335
% concatenate all test handles
34-
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8};
36+
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8, t9};
3537

3638
for i = 1:length(all_tests)
3739
fprintf([10 'Execute ' all_tests{i}.name ' tests:\n\n']);

tests/TestProperty.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function funcs = TestProperty
2+
%TESTPROPERTY % Tests for the nix.Property object
3+
% Detailed explanation goes here
4+
5+
funcs = {};
6+
funcs{end+1} = @test_attrs;
7+
end
8+
9+
%% Test: Access Attributes
10+
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);
14+
15+
assert(~isempty(p.id));
16+
17+
assert(strcmp(p.name, 'ExperimentalCondition'));
18+
assert(isempty(p.definition));
19+
assert(isempty(p.unit));
20+
assert(isempty(s.mapping));
21+
end

tests/TestSection.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
funcs{end+1} = @test_has_section;
1212
funcs{end+1} = @test_attrs;
1313
funcs{end+1} = @test_properties;
14+
funcs{end+1} = @test_open_property;
1415
funcs{end+1} = @test_link;
1516
end
1617

@@ -135,6 +136,15 @@
135136
assert(isempty(f.sections{3}.allProperties));
136137
end
137138

139+
%% Test: Open property by ID and name
140+
function [] = test_open_property( varargin )
141+
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
142+
trial = f.sections{2}.sections{2}.sections{1};
143+
144+
assert(~isempty(trial.open_property(trial.allProperties{1}.id)));
145+
assert(~isempty(trial.open_property(trial.allProperties{1}.name)));
146+
end
147+
138148
%%Test: set, open and remove section link
139149
function [] = test_link( varargin )
140150
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);

0 commit comments

Comments
 (0)