Skip to content

Commit 9626ffd

Browse files
authored
Merge pull request #140 from mpsonntag/sectionFunc
Add missing 'Section' functions
2 parents 6fe5ba1 + d452bc0 commit 9626ffd

File tree

6 files changed

+387
-1
lines changed

6 files changed

+387
-1
lines changed

+nix/Section.m

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
end;
6666
end;
6767

68+
function retList = inherited_properties(obj)
69+
retList = nix.Utils.fetchObjList('Section::inheritedProperties', ...
70+
obj.nix_handle, @nix.Property);
71+
end
72+
6873
% ----------------
6974
% Section methods
7075
% ----------------
@@ -146,5 +151,51 @@
146151
c = nix_mx('Section::propertyCount', obj.nix_handle);
147152
end
148153

154+
% ----------------
155+
% Referring entity methods
156+
% ----------------
157+
158+
function ret = referring_data_arrays(obj, varargin)
159+
ret = obj.referring_util(@nix.DataArray, 'DataArrays', varargin{:});
160+
end
161+
162+
function ret = referring_tags(obj, varargin)
163+
ret = obj.referring_util(@nix.Tag, 'Tags', varargin{:});
164+
end
165+
166+
function ret = referring_multi_tags(obj, varargin)
167+
ret = obj.referring_util(@nix.MultiTag, 'MultiTags', varargin{:});
168+
end
169+
170+
function ret = referring_sources(obj, varargin)
171+
ret = obj.referring_util(@nix.Source, 'Sources', varargin{:});
172+
end
173+
174+
function ret = referring_blocks(obj)
175+
ret = nix.Utils.fetchObjList('Section::referringBlocks', ...
176+
obj.nix_handle, @nix.Block);
177+
end
149178
end;
179+
180+
% ----------------
181+
% Referring utility method
182+
% ----------------
183+
184+
methods(Access=protected)
185+
% referring_util receives a nix entityConstructor, part of a function
186+
% name and varargin to provide abstract access to nix.Section
187+
% referringXXX and referringXXX(Block) methods.
188+
function ret = referring_util(obj, entityConstructor, funcName, varargin)
189+
if (isempty(varargin))
190+
ret = nix.Utils.fetchObjList(strcat('Section::referring', funcName), ...
191+
obj.nix_handle, entityConstructor);
192+
elseif ((size(varargin, 2) > 1) || ...
193+
(~strcmp(class(varargin{1}), 'nix.Block')))
194+
error('Provide either empty arguments or a single Block entity');
195+
else
196+
ret = nix.Utils.fetchObjListByEntity(strcat('Section::referringBlock', funcName), ...
197+
obj.nix_handle, varargin{1}.nix_handle, entityConstructor);
198+
end
199+
end
200+
end
150201
end

+nix/Utils.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
end;
1818
end;
1919

20+
% This method calls the nix-mx function specified by 'nixMxFunc', handing
21+
% over 'handle' as the main nix entity handle and 'related_handle' as a
22+
% second nix entity handle related to the first one.
23+
% 'objConstrucor' requires the Matlab entity constructor of the expected
24+
% returned nix Entities.
25+
function currData = fetchObjListByEntity(nixMxFunc, handle, related_handle, objConstructor)
26+
currList = nix_mx(nixMxFunc, handle, related_handle);
27+
currData = cell(length(currList), 1);
28+
for i = 1:length(currList)
29+
currData{i} = objConstructor(currList{i});
30+
end;
31+
end;
32+
2033
function retCell = fetchObj(nixMxFunc, handle, objConstructor)
2134
sh = nix_mx(nixMxFunc, handle);
2235
if sh ~= 0

nix_mx.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,20 @@ void mexFunction(int nlhs,
346346
.reg("openProperty", GETBYSTR(nix::Property, nix::Section, getProperty))
347347
.reg("deleteProperty", REMOVER(nix::Property, nix::Section, deleteProperty))
348348
.reg("sectionCount", GETTER(nix::ndsize_t, nix::Section, sectionCount))
349-
.reg("propertyCount", GETTER(nix::ndsize_t, nix::Section, propertyCount));
349+
.reg("propertyCount", GETTER(nix::ndsize_t, nix::Section, propertyCount))
350+
.reg("inheritedProperties", GETTER(std::vector<nix::Property>, nix::Section, inheritedProperties))
351+
.reg("referringDataArrays", GETTER(std::vector<nix::DataArray>, nix::Section, referringDataArrays))
352+
.reg("referringTags", GETTER(std::vector<nix::Tag>, nix::Section, referringTags))
353+
.reg("referringMultiTags", GETTER(std::vector<nix::MultiTag>, nix::Section, referringMultiTags))
354+
.reg("referringSources", GETTER(std::vector<nix::Source>, nix::Section, referringSources))
355+
.reg("referringBlocks", GETTER(std::vector<nix::Block>, nix::Section, referringBlocks));
350356
methods->add("Section::properties", nixsection::properties);
351357
methods->add("Section::createProperty", nixsection::createProperty);
352358
methods->add("Section::createPropertyWithValue", nixsection::createPropertyWithValue);
359+
methods->add("Section::referringBlockSources", nixsection::referringBlockSources);
360+
methods->add("Section::referringBlockTags", nixsection::referringBlockTags);
361+
methods->add("Section::referringBlockMultiTags", nixsection::referringBlockMultiTags);
362+
methods->add("Section::referringBlockDataArrays", nixsection::referringBlockDataArrays);
353363

354364
classdef<nix::Feature>("Feature", methods)
355365
.desc(&nixfeature::describe)

src/nixsection.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,28 @@ namespace nixsection {
8181
output.set(0, handle(p));
8282
}
8383

84+
void referringBlockSources(const extractor &input, infusor &output) {
85+
nix::Section currSec = input.entity<nix::Section>(1);
86+
nix::Block currBlock = input.entity<nix::Block>(2);
87+
output.set(0, currSec.referringSources(currBlock));
88+
}
89+
90+
void referringBlockTags(const extractor &input, infusor &output) {
91+
nix::Section currSec = input.entity<nix::Section>(1);
92+
nix::Block currBlock = input.entity<nix::Block>(2);
93+
output.set(0, currSec.referringTags(currBlock));
94+
}
95+
96+
void referringBlockMultiTags(const extractor &input, infusor &output) {
97+
nix::Section currSec = input.entity<nix::Section>(1);
98+
nix::Block currBlock = input.entity<nix::Block>(2);
99+
output.set(0, currSec.referringMultiTags(currBlock));
100+
}
101+
102+
void referringBlockDataArrays(const extractor &input, infusor &output) {
103+
nix::Section currSec = input.entity<nix::Section>(1);
104+
nix::Block currBlock = input.entity<nix::Block>(2);
105+
output.set(0, currSec.referringDataArrays(currBlock));
106+
}
107+
84108
} // namespace nixsection

src/nixsection.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ namespace nixsection {
2121

2222
void createPropertyWithValue(const extractor &input, infusor &output);
2323

24+
void referringBlockSources(const extractor &input, infusor &output);
25+
26+
void referringBlockTags(const extractor &input, infusor &output);
27+
28+
void referringBlockMultiTags(const extractor &input, infusor &output);
29+
30+
void referringBlockDataArrays(const extractor &input, infusor &output);
31+
2432
} // namespace nixsection
2533

2634
#endif

0 commit comments

Comments
 (0)