Skip to content

Commit b8fea64

Browse files
committed
include nix::string_to_data_type
1 parent 277a4d2 commit b8fea64

File tree

7 files changed

+32
-21
lines changed

7 files changed

+32
-21
lines changed

+nix/Block.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
'Block::openDataArray', id_or_name, @nix.DataArray);
2828
end;
2929

30-
function da = create_data_array(obj, name, nixtype, dtype, shape)
30+
%-- As "datatype" provide one of the nix.DataTypes. Alternatively
31+
%-- a string stating one of the datatypes supported by nix can be provided.
32+
function da = create_data_array(obj, name, nixtype, datatype, shape)
3133
handle = nix_mx('Block::createDataArray', obj.nix_handle, ...
32-
name, nixtype, dtype, shape);
34+
name, nixtype, datatype, shape);
3335
da = nix.DataArray(handle);
3436
obj.dataArraysCache.lastUpdate = 0;
3537
end

+nix/DataType.m

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
classdef DataType
2-
%DATATYPE three of the datatypes used in nix
3-
2+
%DATATYPE datatypes supported by nix
3+
44
properties (Constant)
5-
Boolean = uint8(0);
6-
String = uint8(1);
7-
Double = uint8(2);
5+
Boolean = 'bool';
6+
String = 'string';
7+
Double = 'double';
8+
Char = 'char';
9+
Float = 'float';
10+
Int8 = 'int8';
11+
Int16 = 'int16';
12+
Int32 = 'int32';
13+
Int64 = 'int64';
14+
UInt8 = 'uint8';
15+
UInt16 = 'uint16';
16+
UInt32 = 'uint32';
17+
UInt64 = 'uint64';
818
end
9-
10-
end
1119

20+
end

+nix/Section.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@
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));
90+
%-- As "datatype" provide one of the nix.DataTypes. Alternatively
91+
%-- a string stating one of the datatypes supported by nix can be provided.
92+
function p = create_property_data_type(obj, name, datatype)
93+
p = nix.Property(nix_mx('Section::createPropertyDataType', ...
94+
obj.nix_handle, name, datatype));
9295
obj.propsCache.lastUpdate = 0;
9396
end;
9497

src/nixblock.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace nixblock {
2828

2929
std::string name = input.str(2);
3030
std::string type = input.str(3);
31-
nix::DataType dtype = nix::DataType::Double; // FIXME nix::string_to_data_type(input.str(3));
31+
nix::DataType dtype = nix::string_to_data_type(input.str(4));
3232
nix::NDSize size = input.ndsize(5);
3333

3434
nix::DataArray dt = block.createDataArray(name, type, dtype, size);

src/nixsection.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,7 @@ void create_property_data_type(const extractor &input, infusor &output)
6363
{
6464
nix::Section currObj = input.entity<nix::Section>(1);
6565

66-
nix::DataType dtype;
67-
68-
switch (input.num<uint8_t>(3)) {
69-
case 0: dtype = nix::DataType::Bool;
70-
case 1: dtype = nix::DataType::String;
71-
case 2: dtype = nix::DataType::Double;
72-
}
66+
nix::DataType dtype = nix::string_to_data_type(input.str(3));
7367

7468
nix::Property p = currObj.createProperty(input.str(2), dtype);
7569
output.set(0, handle(p));

tests/TestBlock.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
f = nix.File(fullfile(pwd, 'tests', 'testRW.h5'), nix.FileMode.Overwrite);
9191
b = f.createBlock('arraytest', 'nixBlock');
9292
tmp = b.create_data_array('dataArrayTest1', 'nixDataArray', 'double', [1 2]);
93-
tmp = b.create_data_array('dataArrayTest2', 'nixDataArray', 'double', [3 4]);
93+
tmp = b.create_data_array('dataArrayTest2', 'nixDataArray', nix.DataType.Double, [3 4]);
9494

9595
assert(size(b.dataArrays, 1) == 2);
9696
assert(b.delete_data_array(b.dataArrays{2}.id));

tests/TestSection.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@
146146
tmp = s.create_property_data_type('newProperty1', nix.DataType.Double);
147147
tmp = s.create_property_data_type('newProperty2', nix.DataType.Boolean);
148148
tmp = s.create_property_data_type('newProperty3', nix.DataType.String);
149-
assert(size(s.allProperties, 1) == 3);
149+
tmp = s.create_property_data_type('newProperty4', 'double');
150+
tmp = s.create_property_data_type('newProperty5', 'bool');
151+
tmp = s.create_property_data_type('newProperty6', 'string');
152+
assert(size(s.allProperties, 1) == 6);
150153
assert(strcmp(s.allProperties{1}.name, 'newProperty1'));
151154
end
152155

0 commit comments

Comments
 (0)