Skip to content

Commit 81acba2

Browse files
committed
Merge pull request #66 from asobolev/master
Tag refactoring + MetadataMixIn & SourcesMixIn
2 parents 64ebc27 + 146de33 commit 81acba2

File tree

5 files changed

+80
-121
lines changed

5 files changed

+80
-121
lines changed

+nix/Dynamic.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
end
1717
end
1818

19-
methods (Access = protected)
19+
methods (Hidden = true)
2020
function add_dyn_attr(obj, prop, mode)
2121
if nargin < 3
2222
mode = 'r';

+nix/MetadataMixIn.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
classdef MetadataMixIn < handle
2+
%MetadataMixIn
3+
% mixin class for nix entities with metadata
4+
% depends on
5+
% - nix.Entity
6+
7+
properties(Hidden)
8+
metadataCache
9+
end;
10+
11+
methods
12+
function obj = MetadataMixIn()
13+
obj.metadataCache = nix.CacheStruct();
14+
end
15+
16+
function metadata = open_metadata(obj)
17+
[obj.metadataCache, metadata] = nix.Utils.fetchObj(obj.updatedAt, ...
18+
'Tag::openMetadataSection', obj.nix_handle, obj.metadataCache, @nix.Section);
19+
end;
20+
end
21+
22+
end
23+

+nix/SourcesMixIn.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
classdef SourcesMixIn < handle
2+
%SourcesMixIn
3+
% 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)
9+
alias
10+
end
11+
12+
methods
13+
function obj = SourcesMixIn()
14+
obj.add_dyn_relation('sources', @nix.Source);
15+
end
16+
17+
function [] = add_source(obj, add_this)
18+
obj.sourcesCache = nix.Utils.add_entity(obj, ...
19+
add_this, 'nix.Source', ...
20+
strcat(obj.alias, '::addSource'), obj.sourcesCache);
21+
end;
22+
23+
function delCheck = remove_source(obj, del)
24+
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
25+
del, 'nix.Source', strcat(obj.alias, '::removeSource'), ...
26+
obj.sourcesCache);
27+
end;
28+
29+
function retObj = open_source(obj, id_or_name)
30+
retObj = nix.Utils.open_entity(obj, ...
31+
strcat(obj.alias, '::openSource'), id_or_name, ...
32+
@nix.Source);
33+
end;
34+
end
35+
36+
end
37+

+nix/Tag.m

Lines changed: 17 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,25 @@
1-
classdef Tag < nix.Entity
1+
classdef Tag < nix.NamedEntity & nix.MetadataMixIn & nix.SourcesMixIn
22
%Tag nix Tag object
33

4-
properties(Hidden)
5-
info
6-
referencesCache
7-
featuresCache
8-
sourcesCache
9-
metadataCache
10-
end;
4+
properties (Access = protected)
5+
% namespace reference for nix-mx functions
6+
alias = 'Tag'
7+
end
118

12-
properties(Dependent)
13-
id
14-
type
15-
name
16-
definition
17-
position
18-
extent
19-
units
20-
featureCount
21-
sourceCount
22-
referenceCount
23-
24-
references
25-
features
26-
sources
27-
end;
28-
299
methods
3010
function obj = Tag(h)
31-
32-
obj.info = nix_mx('Tag::describe', obj.nix_handle);
33-
34-
obj.referencesCache.lastUpdate = 0;
35-
obj.referencesCache.data = {};
36-
obj.featuresCache.lastUpdate = 0;
37-
obj.featuresCache.data = {};
38-
obj.sourcesCache.lastUpdate = 0;
39-
obj.sourcesCache.data = {};
40-
obj.metadataCache.lastUpdate = 0;
41-
obj.metadataCache.data = {};
42-
end;
43-
44-
function id = get.id(tag)
45-
id = tag.info.id;
46-
end;
47-
48-
function name = get.name(tag)
49-
name = tag.info.name;
50-
end;
51-
52-
function type = get.type(tag)
53-
type = tag.info.type;
54-
end;
55-
56-
function definition = get.definition(tag)
57-
definition = tag.info.definition;
58-
end;
59-
60-
function position = get.position(tag)
61-
position = tag.info.position;
62-
end;
63-
64-
function extent = get.extent(tag)
65-
extent = tag.info.extent;
66-
end;
67-
68-
function units = get.units(tag)
69-
units = tag.info.units;
70-
end;
71-
72-
function featureCount = get.featureCount(tag)
73-
featureCount = tag.info.featureCount;
74-
end;
75-
76-
function sourceCount = get.sourceCount(tag)
77-
sourceCount = tag.info.sourceCount;
78-
end;
79-
80-
function referenceCount = get.referenceCount(tag)
81-
referenceCount = tag.info.referenceCount;
11+
[email protected](h); % this should be first
12+
13+
14+
15+
% assign dynamic properties
16+
obj.add_dyn_attr('position', 'rw');
17+
obj.add_dyn_attr('extent', 'rw');
18+
obj.add_dyn_attr('units', 'rw');
19+
20+
% assign relations
21+
obj.add_dyn_relation('references', @nix.DataArray);
22+
obj.add_dyn_relation('features', @nix.Feature);
8223
end;
8324

8425
% ------------------
@@ -100,11 +41,6 @@
10041
'Tag::openReferenceDataArray', id_or_name, @nix.DataArray);
10142
end;
10243

103-
function da = get.references(obj)
104-
[obj.referencesCache, da] = nix.Utils.fetchObjList(obj.updatedAt, ...
105-
'Tag::references', obj.nix_handle, obj.referencesCache, @nix.DataArray);
106-
end;
107-
10844
function data = retrieve_data(obj, index)
10945
% convert Matlab-like to C-like index
11046
assert(index > 0, 'Subscript indices must be positive');
@@ -123,11 +59,6 @@
12359
retObj = nix.Utils.open_entity(obj, ...
12460
'Tag::openFeature', id_or_name, @nix.Feature);
12561
end;
126-
127-
function feat = get.features(obj)
128-
[obj.featuresCache, feat] = nix.Utils.fetchObjList(obj.updatedAt, ...
129-
'Tag::features', obj.nix_handle, obj.featuresCache, @nix.Feature);
130-
end;
13162

13263
function data = retrieve_feature_data(obj, index)
13364
% convert Matlab-like to C-like index
@@ -138,39 +69,6 @@
13869
% see mkarray.cc(42)
13970
data = permute(tmp, length(size(tmp)):-1:1);
14071
end;
141-
142-
% ------------------
143-
% Sources methods
144-
% ------------------
145-
146-
function [] = add_source(obj, add_this)
147-
obj.sourcesCache = nix.Utils.add_entity(obj, ...
148-
add_this, 'nix.Source', 'Tag::addSource', obj.sourcesCache);
149-
end;
150-
151-
function delCheck = remove_source(obj, del)
152-
[delCheck, obj.sourcesCache] = nix.Utils.delete_entity(obj, ...
153-
del, 'nix.Source', 'Tag::removeSource', obj.sourcesCache);
154-
end;
155-
156-
function retObj = open_source(obj, id_or_name)
157-
retObj = nix.Utils.open_entity(obj, ...
158-
'Tag::openSource', id_or_name, @nix.Source);
159-
end;
160-
161-
function sources = get.sources(obj)
162-
[obj.sourcesCache, sources] = nix.Utils.fetchObjList(obj.updatedAt, ...
163-
'Tag::sources', obj.nix_handle, obj.sourcesCache, @nix.Source);
164-
end;
165-
166-
% ------------------
167-
% Metadata methods
168-
% ------------------
169-
170-
function metadata = open_metadata(obj)
171-
[obj.metadataCache, metadata] = nix.Utils.fetchObj(obj.updatedAt, ...
172-
'Tag::openMetadataSection', obj.nix_handle, obj.metadataCache, @nix.Section);
173-
end;
17472

17573
end;
17674
end

nix_mx.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static void on_exit() {
5555
}
5656

5757
#define GETTER(type, class, name) static_cast<type(class::*)()const>(&class::name)
58+
//#define SETTER(type, class, name) static_cast<void(class::*)(type)>(&class::name)
5859
#define GETBYSTR(type, class, name) static_cast<type(class::*)(const std::string &)const>(&class::name)
5960
#define GETCONTENT(type, class, name) static_cast<type(class::*)()const>(&class::name)
6061
#define GETSOURCES(base__) static_cast<std::vector<nix::Source>(nix::base::EntityWithSources<nix::base::base__>::*)(std::function<bool(const nix::Source &)>)const>(&nix::base::EntityWithSources<nix::base::base__>::sources)
@@ -101,7 +102,6 @@ void mexFunction(int nlhs,
101102

102103
classdef<nix::Block>("Block", methods)
103104
.desc(&nixblock::describe)
104-
//.reg("createDataArray", static_cast<nix::DataArray(nix::Block::*)(const std::string &, const std::string &, nix::DataType, const nix::NDSize &)>(&nix::Block::createDataArray))
105105
.reg("createSource", &nix::Block::createSource)
106106
.reg("createTag", &nix::Block::createTag)
107107
.reg("dataArrays", &nix::Block::dataArrays)
@@ -180,6 +180,7 @@ void mexFunction(int nlhs,
180180
.reg("hasSection", GETBYSTR(bool, nix::Section, hasSection))
181181
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
182182
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent));
183+
//.reg("set_repository", SETTER(const std::string&, nix::Section, repository));
183184
methods->add("Section::properties", nixsection::properties);
184185

185186
classdef<nix::Feature>("Feature", methods)

0 commit comments

Comments
 (0)