Skip to content

Commit eaca919

Browse files
committed
create/delete Property for Section
1 parent 45707f1 commit eaca919

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

+nix/Section.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@
8787
% Property methods
8888
% ----------------
8989

90+
function p = create_property_data_type(obj, name, dtype)
91+
p = nix.Property(nix_mx('Section::createPropertyDataType', obj.nix_handle, name, dtype));
92+
obj.propsCache.lastUpdate = 0;
93+
end;
94+
95+
function delCheck = delete_property(obj, del)
96+
if(isstruct(del) && isfield(del, 'id'))
97+
delID = del.id;
98+
elseif (strcmp(class(del), 'nix.Property'))
99+
delID = del.id;
100+
else
101+
delID = del;
102+
end;
103+
delCheck = nix_mx('Section::deleteProperty', obj.nix_handle, delID);
104+
obj.propsCache.lastUpdate = 0;
105+
end;
106+
90107
function retObj = open_property(obj, id_or_name)
91108
retObj = nix.Utils.open_entity(obj, ...
92109
'Section::openProperty', id_or_name, @nix.Property);

nix_mx.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ void mexFunction(int nlhs,
231231
.reg("set_none_mapping", SETTER(const boost::none_t, nix::Section, mapping))
232232
.reg("createSection", &nix::Section::createSection)
233233
.reg("deleteSection", REMOVER(nix::Section, nix::Section, deleteSection))
234-
.reg("openProperty", GETBYSTR(nix::Property, nix::Section, getProperty));
234+
.reg("openProperty", GETBYSTR(nix::Property, nix::Section, getProperty))
235+
.reg("deleteProperty", REMOVER(nix::Property, nix::Section, deleteProperty));
235236
methods->add("Section::properties", nixsection::properties);
237+
methods->add("Section::createPropertyDataType", nixsection::create_property_data_type);
236238

237239
classdef<nix::Feature>("Feature", methods)
238240
.desc(&nixfeature::describe)

src/nixsection.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,14 @@ void properties(const extractor &input, infusor &output)
5959
output.set(0, lst);
6060
}
6161

62+
void create_property_data_type(const extractor &input, infusor &output)
63+
{
64+
nix::Section currObj = input.entity<nix::Section>(1);
65+
66+
nix::DataType dtype = nix::DataType::Double; // FIXME nix::string_to_data_type(input.str(3));
67+
68+
nix::Property p = currObj.createProperty(input.str(2), dtype);
69+
output.set(0, handle(p));
70+
}
71+
6272
} // namespace nixsection

src/nixsection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace nixsection {
99

1010
void properties(const extractor &input, infusor &output);
1111

12+
void create_property_data_type(const extractor &input, infusor &output);
13+
1214
} // namespace nixfile
1315

1416
#endif

tests/TestSection.m

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
funcs{end+1} = @test_has_section;
1212
funcs{end+1} = @test_attrs;
1313
funcs{end+1} = @test_properties;
14+
funcs{end+1} = @test_create_property_data_type;
15+
funcs{end+1} = @test_delete_property;
1416
funcs{end+1} = @test_open_property;
1517
funcs{end+1} = @test_link;
1618
end
@@ -136,6 +138,36 @@
136138
assert(isempty(f.sections{3}.allProperties));
137139
end
138140

141+
%% Test: Create property by data type
142+
function [] = test_create_property_data_type( varargin )
143+
f = nix.File(fullfile(pwd,'tests','testRW.h5'), nix.FileMode.Overwrite);
144+
s = f.createSection('mainSection', 'nixSection');
145+
146+
newProperty = s.create_property_data_type('newProperty', 'double');
147+
assert(strcmp(s.allProperties{1}.name, 'newProperty'));
148+
disp('Test MultiTag: create property by data type ... TODO (proper data type implementation)');
149+
end
150+
151+
%% Test: Delete property by entity, propertyStruct, ID and name
152+
function [] = test_delete_property( varargin )
153+
f = nix.File(fullfile(pwd,'tests','testRW.h5'), nix.FileMode.Overwrite);
154+
s = f.createSection('mainSection', 'nixSection');
155+
tmp = s.create_property_data_type('newProperty1', 'double');
156+
tmp = s.create_property_data_type('newProperty2', 'double');
157+
tmp = s.create_property_data_type('newProperty3', 'double');
158+
tmp = s.create_property_data_type('newProperty4', 'double');
159+
160+
assert(s.delete_property('newProperty4'));
161+
assert(s.delete_property(s.allProperties{3}.id));
162+
delProp = s.open_property(s.allProperties{2}.id);
163+
assert(s.delete_property(delProp));
164+
assert(s.delete_property(s.allProperties{1}));
165+
166+
assert(~s.delete_property('I do not exist'));
167+
168+
disp('Test MultiTag: delete property by data type ... TODO (proper data type implementation)');
169+
end
170+
139171
%% Test: Open property by ID and name
140172
function [] = test_open_property( varargin )
141173
f = nix.File(fullfile(pwd, 'tests', 'test.h5'), nix.FileMode.ReadOnly);
@@ -145,7 +177,7 @@
145177
assert(~isempty(trial.open_property(trial.allProperties{1}.name)));
146178
end
147179

148-
%%Test: set, open and remove section link
180+
%% Test: set, open and remove section link
149181
function [] = test_link( varargin )
150182
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
151183
mainSec = f.createSection('mainSection', 'nixSection');

0 commit comments

Comments
 (0)