Skip to content

Commit 9a79c5d

Browse files
committed
[Matlab] Add nix.Utils.createEntityArray function
Introduced to reduce redundancy in nix.Utils functions.
1 parent bfd9ef2 commit 9a79c5d

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

+nix/Utils.m

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@
1010

1111
methods(Static)
1212

13-
function rdata = fetchObjList(nixMxFunc, handle, objConstructor)
14-
currList = nix_mx(nixMxFunc, handle);
15-
rdata = cell(length(currList), 1);
16-
for i = 1:length(currList)
17-
rdata{i} = objConstructor(currList{i});
13+
function r = createEntityArray(list, objConstructor)
14+
r = cell(length(list), 1);
15+
for i = 1:length(list)
16+
r{i} = objConstructor(list{i});
1817
end
1918
end
2019

20+
function r = fetchObjList(nixMxFunc, handle, objConstructor)
21+
list = nix_mx(nixMxFunc, handle);
22+
r = nix.Utils.createEntityArray(list, objConstructor);
23+
end
24+
2125
% This method calls the nix-mx function specified by 'nixMxFunc', handing
2226
% over 'handle' as the main nix entity handle and 'related_handle' as a
2327
% second nix entity handle related to the first one.
24-
% 'objConstrucor' requires the Matlab entity constructor of the expected
28+
% 'objConstructor' requires the Matlab entity constructor of the expected
2529
% returned nix Entities.
26-
function rdata = fetchObjListByEntity(nixMxFunc, handle, related_handle, objConstructor)
27-
currList = nix_mx(nixMxFunc, handle, related_handle);
28-
rdata = cell(length(currList), 1);
29-
for i = 1:length(currList)
30-
rdata{i} = objConstructor(currList{i});
31-
end
30+
function r = fetchObjListByEntity(nixMxFunc, handle, related_handle, objConstructor)
31+
list = nix_mx(nixMxFunc, handle, related_handle);
32+
r = nix.Utils.createEntityArray(list, objConstructor);
3233
end
3334

3435
function r = fetchObj(nixMxFunc, handle, objConstructor)
@@ -101,25 +102,21 @@
101102
end
102103
end
103104

104-
function rdata = filter(obj, filter, val, mxMethod, objConstructor)
105+
function r = filter(obj, filter, val, mxMethod, objConstructor)
105106
valid = nix.Utils.valid_filter(filter, val);
106107
if (~isempty(valid))
107108
error(valid);
108109
end
109110

110-
currList = nix_mx(mxMethod, obj.nix_handle, uint8(filter), val);
111-
rdata = cell(length(currList), 1);
112-
for i = 1:length(currList)
113-
rdata{i} = objConstructor(currList{i});
114-
end
111+
list = nix_mx(mxMethod, obj.nix_handle, uint8(filter), val);
112+
r = nix.Utils.createEntityArray(list, objConstructor);
115113
end
116114

117115
% -----------------------------------------------------------
118116
% findXXX helper functions
119117
% -----------------------------------------------------------
120118

121-
function rdata = find(obj, max_depth, filter, val, ...
122-
mxMethod, objConstructor)
119+
function r = find(obj, max_depth, filter, val, mxMethod, objConstructor)
123120
if (~isnumeric(max_depth))
124121
error('Provide a valid search depth');
125122
end
@@ -129,13 +126,8 @@
129126
error(valid);
130127
end
131128

132-
currList = nix_mx(mxMethod, ...
133-
obj.nix_handle, max_depth, uint8(filter), val);
134-
135-
rdata = cell(length(currList), 1);
136-
for i = 1:length(currList)
137-
rdata{i} = objConstructor(currList{i});
138-
end
129+
list = nix_mx(mxMethod, obj.nix_handle, max_depth, uint8(filter), val);
130+
r = nix.Utils.createEntityArray(list, objConstructor);
139131
end
140132

141133
% -----------------------------------------------------------

0 commit comments

Comments
 (0)