Skip to content

Commit 62dfc68

Browse files
committed
Merge pull request #68 from asobolev/master
Dynamic Attributes + SourcesMixIn / MetadataMixIn integrated
2 parents 114bcab + 2df1013 commit 62dfc68

File tree

13 files changed

+101
-350
lines changed

13 files changed

+101
-350
lines changed

+nix/Block.m

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
classdef Block < nix.NamedEntity
1+
classdef Block < nix.NamedEntity & nix.MetadataMixIn
22
%Block nix Block object
3-
4-
properties (Access = protected)
3+
4+
properties (Hidden)
55
% namespace reference for nix-mx functions
66
alias = 'Block'
77
end
88

9-
properties(Hidden)
10-
metadataCache
11-
end
12-
139
methods
1410
function obj = Block(h)
1511
12+
1613

1714
% assign relations
18-
obj.add_dyn_relation('dataArrays', @nix.DataArray);
19-
obj.add_dyn_relation('sources', @nix.Source);
20-
obj.add_dyn_relation('tags', @nix.Tag);
21-
obj.add_dyn_relation('multiTags', @nix.MultiTag);
22-
23-
obj.metadataCache = nix.CacheStruct();
15+
nix.Dynamic.add_dyn_relation(obj, 'dataArrays', @nix.DataArray);
16+
nix.Dynamic.add_dyn_relation(obj, 'sources', @nix.Source);
17+
nix.Dynamic.add_dyn_relation(obj, 'tags', @nix.Tag);
18+
nix.Dynamic.add_dyn_relation(obj, 'multiTags', @nix.MultiTag);
2419
end;
2520

2621
% -----------------
@@ -126,15 +121,5 @@
126121
[delCheck, obj.multiTagsCache] = nix.Utils.delete_entity(obj, ...
127122
del, 'nix.MultiTag', 'Block::deleteMultiTag', obj.multiTagsCache);
128123
end;
129-
130-
% -----------------
131-
% Metadata methods
132-
% -----------------
133-
134-
function metadata = open_metadata(obj)
135-
[obj.metadataCache, metadata] = nix.Utils.fetchObj(obj.updatedAt, ...
136-
'Block::openMetadataSection', obj.nix_handle, obj.metadataCache, @nix.Section);
137-
end;
138-
139124
end;
140125
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: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
classdef Dynamic < dynamicprops
2-
%Dynamic class that dynamically assigns properties
1+
classdef Dynamic
2+
%Dynamic class (with static methods hehe)
3+
% implements methods to dynamically assigns properties
34

4-
properties (Abstract, Access = protected)
5-
alias
6-
end
7-
8-
properties (Access = protected)
9-
info
10-
end
11-
12-
methods
13-
function obj = Dynamic()
14-
% fetch all object attrs
15-
obj.info = nix_mx(strcat(obj.alias, '::describe'), obj.nix_handle);
16-
end
17-
end
18-
19-
methods (Hidden = true)
5+
methods (Static)
206
function add_dyn_attr(obj, prop, mode)
217
if nargin < 3
228
mode = 'r';
239
end
24-
10+
2511
% create dynamic property
2612
p = addprop(obj, prop);
2713

@@ -60,6 +46,7 @@ function add_dyn_relation(obj, name, constructor)
6046
% same property but returns Map
6147
rel_map = addprop(obj, strcat(name, 'Map'));
6248
rel_map.GetMethod = @get_as_map;
49+
rel_map.Hidden = true;
6350

6451
function val = get_method(obj)
6552
[obj.(cacheAttr), val] = nix.Utils.fetchObjList(obj.updatedAt, ...

+nix/Entity.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
classdef Entity < handle
1+
classdef Entity < dynamicprops
22
%Entity base class for nix entities
33
% handles object lifetime
44

5-
properties(Hidden)
5+
properties (Hidden)
66
nix_handle
7+
info
8+
end
9+
10+
properties (Abstract, Hidden)
11+
alias
712
end
813

914
methods
1015
function obj = Entity(h)
1116
obj.nix_handle = h;
17+
18+
% fetch all object attrs
19+
obj.info = nix_mx(strcat(obj.alias, '::describe'), obj.nix_handle);
1220
end
1321

1422
function delete(obj)

+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: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
%File nix File object
33

44
properties(Hidden)
5-
info
6-
blocksCache;
7-
sectionsCache;
5+
% namespace reference for nix-mx functions
6+
alias = 'File'
87
end;
98

10-
properties(Dependent)
11-
blocks
12-
sections
13-
end
14-
159
methods
1610
function obj = File(path, mode)
1711
if ~exist('mode', 'var')
1812
mode = nix.FileMode.ReadWrite; %default to ReadWrite
1913
end
2014
h = nix_mx('File::open', path, mode);
2115
22-
23-
obj.blocksCache.lastUpdate = 0;
24-
obj.blocksCache.data = {};
25-
obj.sectionsCache.lastUpdate = 0;
26-
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);
2720

2821
obj.info = nix_mx('File::describe', obj.nix_handle);
2922
end
@@ -37,11 +30,6 @@
3730
'File::openBlock', id_or_name, @nix.Block);
3831
end
3932

40-
function blocks = get.blocks(obj)
41-
[obj.blocksCache, blocks] = nix.Utils.fetchObjList(obj.updatedAt, ...
42-
'File::blocks', obj.nix_handle, obj.blocksCache, @nix.Block);
43-
end
44-
4533
function newBlock = createBlock(obj, name, type)
4634
newBlock = nix.Block(nix_mx('File::createBlock', obj.nix_handle, name, type));
4735
obj.blocksCache.lastUpdate = 0;
@@ -60,11 +48,6 @@
6048
retObj = nix.Utils.open_entity(obj, ...
6149
'File::openSection', id_or_name, @nix.Section);
6250
end
63-
64-
function sections = get.sections(obj)
65-
[obj.sectionsCache, sections] = nix.Utils.fetchObjList(obj.updatedAt, ...
66-
'File::sections', obj.nix_handle, obj.sectionsCache, @nix.Section);
67-
end;
6851

6952
function newSec = createSection(obj, name, type)
7053
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)