Skip to content

Commit 30ed627

Browse files
authored
Merge pull request #138 from mpsonntag/completeProperty
Add missing 'Property' functions
2 parents 1741ba7 + 9fd5b06 commit 30ed627

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

+nix/Property.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@
6161
function c = value_count(obj)
6262
c = nix_mx('Property::valueCount', obj.nix_handle);
6363
end
64+
65+
function [] = values_delete(obj)
66+
nix_mx('Property::deleteValues', obj.nix_handle);
67+
end
68+
69+
% return value 0 means name and id of two properties are
70+
% identical, any other value means either name or id differ.
71+
function cmp_val = compare(obj, property)
72+
if (~strcmp(class(property), class(obj)))
73+
error('Function only supports comparison of Properties.');
74+
end
75+
cmp_val = nix_mx('Property::compare', obj.nix_handle, property.nix_handle);
76+
end
77+
6478
end
6579

6680
end

nix_mx.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,12 @@ void mexFunction(int nlhs,
362362
.reg("setNoneUnit", SETTER(const boost::none_t, nix::Property, unit))
363363
.reg("setMapping", SETTER(const std::string&, nix::Property, mapping))
364364
.reg("setNoneMapping", SETTER(const boost::none_t, nix::Property, mapping))
365-
.reg("valueCount", GETTER(nix::ndsize_t, nix::Property, valueCount));
365+
.reg("valueCount", GETTER(nix::ndsize_t, nix::Property, valueCount))
366+
.reg("setNoneValue", SETTER(const boost::none_t, nix::Property, values));
366367
methods->add("Property::values", nixproperty::values);
367368
methods->add("Property::updateValues", nixproperty::updateValues);
369+
methods->add("Property::deleteValues", nixproperty::deleteValues);
370+
methods->add("Property::compare", nixproperty::compare);
368371

369372
classdef<nix::SetDimension>("SetDimension", methods)
370373
.desc(&nixdimensions::describe)

src/nixproperty.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,15 @@ namespace nixproperty {
6464
prop.values(getVals);
6565
}
6666

67+
void deleteValues(const extractor &input, infusor &output) {
68+
nix::Property prop = input.entity<nix::Property>(1);
69+
prop.deleteValues();
70+
}
71+
72+
void compare(const extractor &input, infusor &output) {
73+
nix::Property pm = input.entity<nix::Property>(1);
74+
nix::Property pc = input.entity<nix::Property>(2);
75+
output.set(0, pm.compare(pc));
76+
}
77+
6778
} // namespace nixproperty

src/nixproperty.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace nixproperty {
1919

2020
void updateValues(const extractor &input, infusor &output);
2121

22+
void deleteValues(const extractor &input, infusor &output);
23+
24+
void compare(const extractor &input, infusor &output);
25+
2226
} // namespace nixproperty
2327

2428
#endif

tests/TestProperty.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
funcs{end+1} = @test_update_values;
1616
funcs{end+1} = @test_values;
1717
funcs{end+1} = @test_value_count;
18+
funcs{end+1} = @test_values_delete;
19+
funcs{end+1} = @test_property_compare;
1820
end
1921

2022
%% Test: Access Attributes
@@ -128,3 +130,43 @@
128130
pid = f.sections{1}.allProperties{1}.id;
129131
assert(f.sections{1}.open_property(pid).value_count() == 1);
130132
end
133+
134+
%% Test: Delete values
135+
function [] = test_values_delete( varargin )
136+
testFile = fullfile(pwd,'tests','testRW.h5');
137+
f = nix.File(testFile, nix.FileMode.Overwrite);
138+
s = f.create_section('testSection', 'nixSection');
139+
140+
p = s.create_property_with_value('property1', {true, false, true});
141+
assert(~isempty(p.values));
142+
p.values_delete();
143+
assert(isempty(p.values));
144+
145+
clear p s f;
146+
f = nix.File(testFile, nix.FileMode.ReadOnly);
147+
assert(isempty(f.sections{1}.allProperties{1}.values));
148+
end
149+
150+
%% Test: Compare properties
151+
function [] = test_property_compare( varargin )
152+
testFile = fullfile(pwd,'tests','testRW.h5');
153+
f = nix.File(testFile, nix.FileMode.Overwrite);
154+
s1 = f.create_section('testSection1', 'nixSection');
155+
s2 = f.create_section('testSection2', 'nixSection');
156+
157+
p = s1.create_property_with_value('property', {true, false, true});
158+
159+
% test invalid property comparison
160+
try
161+
p.compare('I shall crash and burn');
162+
catch ME
163+
assert(strcmp(ME.message, 'Function only supports comparison of Properties.'));
164+
end
165+
166+
% test property equal comparison
167+
assert(~p.compare(p));
168+
169+
% test property not eqal
170+
pNEq = s2.create_property_with_value('property', {true, false});
171+
assert(p.compare(pNEq)~=0);
172+
end

0 commit comments

Comments
 (0)