Skip to content

Commit e511e22

Browse files
committed
refactored Dynamic into independent static class
1 parent 114bcab commit e511e22

File tree

8 files changed

+43
-56
lines changed

8 files changed

+43
-56
lines changed

+nix/Block.m

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
classdef Block < nix.NamedEntity
22
%Block nix Block object
3-
4-
properties (Access = protected)
3+
4+
properties (Hidden)
55
% namespace reference for nix-mx functions
66
alias = 'Block'
7-
end
8-
9-
properties(Hidden)
107
metadataCache
118
end
129

@@ -15,10 +12,10 @@
1512
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);
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);
2219

2320
obj.metadataCache = nix.CacheStruct();
2421
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 (all methods are static 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/File.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
%File nix File object
33

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

+nix/NamedEntity.m

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
classdef NamedEntity < nix.Entity & nix.Dynamic
1+
classdef NamedEntity < nix.Entity
22
%NamedEntity
33
% base class for nix entities with name/type/definition
44

55
methods
66
function obj = NamedEntity(h)
77
8-
98

109
% assign dynamic properties
11-
obj.add_dyn_attr('id', 'r');
12-
obj.add_dyn_attr('name', 'r');
13-
obj.add_dyn_attr('type', 'rw');
14-
obj.add_dyn_attr('definition', 'rw');
10+
nix.Dynamic.add_dyn_attr(obj, 'id', 'r');
11+
nix.Dynamic.add_dyn_attr(obj, 'name', 'r');
12+
nix.Dynamic.add_dyn_attr(obj, 'type', 'rw');
13+
nix.Dynamic.add_dyn_attr(obj, 'definition', 'rw');
1514
end
1615
end
1716

+nix/Section.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
%SECTION Metadata Section class
33
% NIX metadata section
44

5-
properties (Access = protected)
5+
properties(Hidden)
66
% namespace reference for nix-mx functions
77
alias = 'Section'
8-
end
9-
10-
properties(Hidden)
118
propsCache
129
end;
1310

@@ -21,11 +18,11 @@
2118
2219

2320
% assign dynamic properties
24-
obj.add_dyn_attr('repository', 'rw');
25-
obj.add_dyn_attr('mapping', 'rw');
21+
nix.Dynamic.add_dyn_attr(obj, 'repository', 'rw');
22+
nix.Dynamic.add_dyn_attr(obj, 'mapping', 'rw');
2623

2724
% assign relations
28-
obj.add_dyn_relation('sections', @nix.Section);
25+
nix.Dynamic.add_dyn_relation(obj, 'sections', @nix.Section);
2926

3027
obj.propsCache = nix.CacheStruct();
3128
end;

+nix/SourcesMixIn.m

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
classdef SourcesMixIn < handle
22
%SourcesMixIn
33
% mixin class for nix entities that can be related with sources
4-
% depends on
5-
% - nix.Entity
6-
% - nix.Dynamic
7-
8-
properties (Abstract, Access = protected)
4+
5+
properties (Abstract, Hidden)
96
alias
107
end
118

129
methods
1310
function obj = SourcesMixIn()
14-
obj.add_dyn_relation('sources', @nix.Source);
11+
nix.Dynamic.add_dyn_relation(obj, 'sources', @nix.Source);
1512
end
1613

1714
function [] = add_source(obj, add_this)

+nix/Tag.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef Tag < nix.NamedEntity & nix.MetadataMixIn & nix.SourcesMixIn
22
%Tag nix Tag object
33

4-
properties (Access = protected)
4+
properties (Hidden)
55
% namespace reference for nix-mx functions
66
alias = 'Tag'
77
end
@@ -13,13 +13,13 @@
1313
1414

1515
% assign dynamic properties
16-
obj.add_dyn_attr('position', 'rw');
17-
obj.add_dyn_attr('extent', 'rw');
18-
obj.add_dyn_attr('units', 'rw');
16+
nix.Dynamic.add_dyn_attr(obj, 'position', 'rw');
17+
nix.Dynamic.add_dyn_attr(obj, 'extent', 'rw');
18+
nix.Dynamic.add_dyn_attr(obj, 'units', 'rw');
1919

2020
% assign relations
21-
obj.add_dyn_relation('references', @nix.DataArray);
22-
obj.add_dyn_relation('features', @nix.Feature);
21+
nix.Dynamic.add_dyn_relation(obj, 'references', @nix.DataArray);
22+
nix.Dynamic.add_dyn_relation(obj, 'features', @nix.Feature);
2323
end;
2424

2525
% ------------------

0 commit comments

Comments
 (0)