Skip to content

Commit edbd958

Browse files
committed
Merge pull request #79 from mpsonntag/sectionProperty
Datatype entity, Setter/getter methods for Property
2 parents c206f0c + 166b135 commit edbd958

File tree

13 files changed

+195
-15
lines changed

13 files changed

+195
-15
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
classdef DataType
2+
%DATATYPE datatypes supported by nix
3+
4+
properties (Constant)
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';
18+
end
19+
20+
end

+nix/Property.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
properties(Hidden)
66
% namespace reference for nix-mx functions
77
alias = 'Property'
8+
valuesCache
9+
end;
10+
11+
properties(Dependent)
12+
values
813
end;
914

1015
methods
@@ -14,7 +19,15 @@
1419
% assign dynamic properties
1520
nix.Dynamic.add_dyn_attr(obj, 'unit', 'rw');
1621
nix.Dynamic.add_dyn_attr(obj, 'mapping', 'rw');
22+
nix.Dynamic.add_dyn_attr(obj, 'datatype', 'r');
23+
24+
obj.valuesCache = nix.CacheStruct();
1725
end;
26+
27+
function retVals = get.values(obj)
28+
[obj.valuesCache, retVals] = nix.Utils.fetchPropList(obj.updatedAt, ...
29+
'Property::values', obj.nix_handle, obj.valuesCache);
30+
end
1831
end
1932

2033
end

+nix/Section.m

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

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(obj, name, datatype)
93+
p = nix.Property(nix_mx('Section::createProperty', ...
94+
obj.nix_handle, name, datatype));
95+
obj.propsCache.lastUpdate = 0;
96+
end;
97+
98+
function delCheck = delete_property(obj, del)
99+
if(isstruct(del) && isfield(del, 'id'))
100+
delID = del.id;
101+
elseif (strcmp(class(del), 'nix.Property'))
102+
delID = del.id;
103+
else
104+
delID = del;
105+
end;
106+
delCheck = nix_mx('Section::deleteProperty', obj.nix_handle, delID);
107+
obj.propsCache.lastUpdate = 0;
108+
end;
109+
90110
function retObj = open_property(obj, id_or_name)
91111
retObj = nix.Utils.open_entity(obj, ...
92112
'Section::openProperty', id_or_name, @nix.Property);

nix_mx.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,24 @@ 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::createProperty", nixsection::create_property);
236238

237239
classdef<nix::Feature>("Feature", methods)
238240
.desc(&nixfeature::describe)
239241
.reg("openData", GETCONTENT(nix::DataArray, nix::Feature, data));
240242

241243
classdef<nix::Property>("Property", methods)
242-
.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));
251+
methods->add("Property::values", nixproperty::values);
243252

244253
mexAtExit(on_exit);
245254
});

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/nixproperty.cc

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,43 @@ 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

24-
} // namespace nixproperty
27+
void values(const extractor &input, infusor &output)
28+
{
29+
nix::Property prop = input.entity<nix::Property>(1);
30+
std::vector<nix::Value> vals = prop.values();
31+
32+
const mwSize size = static_cast<mwSize>(vals.size());
33+
mxArray *lst = mxCreateCellArray(1, &size);
34+
35+
for (size_t i = 0; i < vals.size(); i++) {
36+
37+
nix::Value pr = vals[i];
38+
39+
struct_builder sb({ 1 }, { "value", "uncertainty", "checksum", "encoder", "filename", "reference" });
40+
41+
sb.set(make_mx_array(pr));
42+
sb.set(pr.uncertainty);
43+
sb.set(pr.checksum);
44+
sb.set(pr.checksum);
45+
sb.set(pr.filename);
46+
sb.set(pr.reference);
47+
48+
mxSetCell(lst, i, sb.array());
49+
}
50+
51+
output.set(0, lst);
52+
}
53+
54+
} // namespace nixproperty

src/nixproperty.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace nixproperty {
77

88
mxArray *describe(const nix::Property &prop);
99

10+
void values(const extractor &input, infusor &output);
11+
1012
} // namespace nixproperty
1113

12-
#endif
14+
#endif

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(const extractor &input, infusor &output)
63+
{
64+
nix::Section currObj = input.entity<nix::Section>(1);
65+
66+
nix::DataType dtype = 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(const extractor &input, infusor &output);
13+
1214
} // namespace nixfile
1315

1416
#endif

0 commit comments

Comments
 (0)