Skip to content

Commit ea0cdbf

Browse files
committed
sources / metadata mix-ins refactoring + dynamic attributes
1 parent e511e22 commit ea0cdbf

File tree

8 files changed

+60
-296
lines changed

8 files changed

+60
-296
lines changed

+nix/Block.m

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
classdef Block < nix.NamedEntity
1+
classdef Block < nix.NamedEntity & nix.MetadataMixIn
22
%Block nix Block object
33

44
properties (Hidden)
55
% namespace reference for nix-mx functions
66
alias = 'Block'
7-
metadataCache
87
end
98

109
methods
1110
function obj = Block(h)
1211
12+
1313

1414
% assign relations
1515
nix.Dynamic.add_dyn_relation(obj, 'dataArrays', @nix.DataArray);
1616
nix.Dynamic.add_dyn_relation(obj, 'sources', @nix.Source);
1717
nix.Dynamic.add_dyn_relation(obj, 'tags', @nix.Tag);
1818
nix.Dynamic.add_dyn_relation(obj, 'multiTags', @nix.MultiTag);
19-
20-
obj.metadataCache = nix.CacheStruct();
2119
end;
2220

2321
% -----------------
@@ -123,15 +121,5 @@
123121
[delCheck, obj.multiTagsCache] = nix.Utils.delete_entity(obj, ...
124122
del, 'nix.MultiTag', 'Block::deleteMultiTag', obj.multiTagsCache);
125123
end;
126-
127-
% -----------------
128-
% Metadata methods
129-
% -----------------
130-
131-
function metadata = open_metadata(obj)
132-
[obj.metadataCache, metadata] = nix.Utils.fetchObj(obj.updatedAt, ...
133-
'Block::openMetadataSection', obj.nix_handle, obj.metadataCache, @nix.Section);
134-
end;
135-
136124
end;
137125
end

+nix/DataArray.m

Lines changed: 16 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,32 @@
1-
classdef DataArray < nix.Entity
1+
classdef DataArray < nix.NamedEntity & nix.MetadataMixIn & nix.SourcesMixIn
22
%DataArray nix DataArray object
33

4-
properties(Hidden)
5-
info
6-
sourcesCache
7-
metadataCache
8-
end;
9-
4+
properties (Hidden)
5+
% namespace reference for nix-mx functions
6+
alias = 'DataArray'
7+
end
8+
109
properties(Dependent)
11-
id
12-
type
13-
name
14-
definition
15-
label
16-
shape
17-
unit
18-
dimensions
19-
polynom_coefficients
20-
21-
sources
10+
dimensions % should not be dynamic due to complex set operation
2211
end;
2312

2413
methods
2514
function obj = DataArray(h)
26-
15+
16+
17+
2718

28-
obj.sourcesCache.lastUpdate = 0;
29-
obj.sourcesCache.data = {};
30-
obj.metadataCache.lastUpdate = 0;
31-
obj.metadataCache.data = {};
19+
% assign dynamic properties
20+
nix.Dynamic.add_dyn_attr(obj, 'label', 'rw');
21+
nix.Dynamic.add_dyn_attr(obj, 'unit', 'rw');
22+
nix.Dynamic.add_dyn_attr(obj, 'expansionOrigin', 'rw');
23+
nix.Dynamic.add_dyn_attr(obj, 'polynom_coefficients', 'rw');
24+
nix.Dynamic.add_dyn_attr(obj, 'shape', 'rw');
3225
end;
3326

34-
function nfo = get.info(obj)
35-
nfo = nix_mx('DataArray::describe', obj.nix_handle);
36-
end
37-
38-
function id = get.id(obj)
39-
id = obj.info.id;
40-
end;
41-
42-
function type = get.type(obj)
43-
type = obj.info.type;
44-
end;
45-
46-
function name = get.name(obj)
47-
name = obj.info.name;
48-
end;
49-
50-
function definition = get.definition(obj)
51-
definition = obj.info.definition;
52-
end;
53-
54-
function label = get.label(obj)
55-
label = obj.info.label;
56-
end;
57-
58-
function shape = get.shape(obj)
59-
shape = obj.info.shape;
60-
end;
61-
62-
function unit = get.unit(obj)
63-
unit = obj.info.unit;
64-
end;
65-
6627
function dimensions = get.dimensions(obj)
6728
dimensions = obj.info.dimensions;
6829
end;
69-
70-
function polynom_coefficients = get.polynom_coefficients(obj)
71-
polynom_coefficients = obj.info.polynom_coefficients;
72-
end;
7330

7431
% -----------------
7532
% Data access methods
@@ -89,32 +46,5 @@ function write_all(obj, data) % TODO add (optional) offset
8946
nix_mx('DataArray::writeAll', obj.nix_handle, tmp);
9047
end;
9148

92-
% -----------------
93-
% Sources methods
94-
% -----------------
95-
96-
function [] = add_source(obj, add_this)
97-
obj.sourcesCache = nix.Utils.add_entity(obj, ...
98-
add_this, 'nix.Source', 'DataArray::addSource', obj.sourcesCache);
99-
end;
100-
101-
function delCheck = remove_source(obj, del)
102-
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
103-
del, 'nix.Source', 'DataArray::removeSource', obj.sourcesCache);
104-
end;
105-
106-
function sources = get.sources(obj)
107-
[obj.sourcesCache, sources] = nix.Utils.fetchObjList(obj.updatedAt, ...
108-
'DataArray::sources', obj.nix_handle, obj.sourcesCache, @nix.Source);
109-
end;
110-
111-
% -----------------
112-
% Metadata methods
113-
% -----------------
114-
115-
function metadata = open_metadata(obj)
116-
[obj.metadataCache, metadata] = nix.Utils.fetchObj(obj.updatedAt, ...
117-
'DataArray::openMetadataSection', obj.nix_handle, obj.metadataCache, @nix.Section);
118-
end;
11949
end;
12050
end

+nix/Dynamic.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef Dynamic
2-
%Dynamic class (all methods are static hehe)
2+
%Dynamic class (with static methods hehe)
33
% implements methods to dynamically assigns properties
44

55
methods (Static)

+nix/Feature.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
classdef Feature < nix.Entity
22
%Feature nix Feature object
33

4-
properties(Hidden)
5-
info
6-
end;
4+
properties (Hidden)
5+
% namespace reference for nix-mx functions
6+
alias = 'Feature'
7+
end
78

89
properties(Dependent)
910
id
@@ -12,7 +13,6 @@
1213
methods
1314
function obj = Feature(h)
1415
15-
obj.info = nix_mx('Feature::describe', obj.nix_handle);
1616
end;
1717

1818
function id = get.id(obj)

+nix/File.m

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@
44
properties(Hidden)
55
% namespace reference for nix-mx functions
66
alias = 'File'
7-
8-
blocksCache;
9-
sectionsCache;
107
end;
118

12-
properties(Dependent)
13-
blocks
14-
sections
15-
end
16-
179
methods
1810
function obj = File(path, mode)
1911
if ~exist('mode', 'var')
2012
mode = nix.FileMode.ReadWrite; %default to ReadWrite
2113
end
2214
h = nix_mx('File::open', path, mode);
2315
24-
25-
obj.blocksCache.lastUpdate = 0;
26-
obj.blocksCache.data = {};
27-
obj.sectionsCache.lastUpdate = 0;
28-
obj.sectionsCache.data = {};
16+
17+
% assign relations
18+
nix.Dynamic.add_dyn_relation(obj, 'blocks', @nix.Block);
19+
nix.Dynamic.add_dyn_relation(obj, 'sections', @nix.Section);
2920

3021
obj.info = nix_mx('File::describe', obj.nix_handle);
3122
end
@@ -39,11 +30,6 @@
3930
'File::openBlock', id_or_name, @nix.Block);
4031
end
4132

42-
function blocks = get.blocks(obj)
43-
[obj.blocksCache, blocks] = nix.Utils.fetchObjList(obj.updatedAt, ...
44-
'File::blocks', obj.nix_handle, obj.blocksCache, @nix.Block);
45-
end
46-
4733
function newBlock = createBlock(obj, name, type)
4834
newBlock = nix.Block(nix_mx('File::createBlock', obj.nix_handle, name, type));
4935
obj.blocksCache.lastUpdate = 0;
@@ -62,11 +48,6 @@
6248
retObj = nix.Utils.open_entity(obj, ...
6349
'File::openSection', id_or_name, @nix.Section);
6450
end
65-
66-
function sections = get.sections(obj)
67-
[obj.sectionsCache, sections] = nix.Utils.fetchObjList(obj.updatedAt, ...
68-
'File::sections', obj.nix_handle, obj.sectionsCache, @nix.Section);
69-
end;
7051

7152
function newSec = createSection(obj, name, type)
7253
newSec = nix.Section(nix_mx('File::createSection', obj.nix_handle, name, type));

+nix/MetadataMixIn.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
% mixin class for nix entities with metadata
44
% depends on
55
% - nix.Entity
6-
6+
7+
properties (Abstract, Hidden)
8+
alias
9+
end
10+
711
properties(Hidden)
812
metadataCache
913
end;
@@ -14,8 +18,10 @@
1418
end
1519

1620
function metadata = open_metadata(obj)
17-
[obj.metadataCache, metadata] = nix.Utils.fetchObj(obj.updatedAt, ...
18-
'Tag::openMetadataSection', obj.nix_handle, obj.metadataCache, @nix.Section);
21+
[obj.metadataCache, metadata] = nix.Utils.fetchObj(...
22+
obj.updatedAt, ...
23+
strcat(obj.alias, '::openMetadataSection'), ...
24+
obj.nix_handle, obj.metadataCache, @nix.Section);
1925
end;
2026
end
2127

0 commit comments

Comments
 (0)