Skip to content

Commit 66f4ee8

Browse files
committed
[Matlab] Add nix.Utils.createEntity function
Introduced to reduce redundancy in nix.Utils, nix.MultiTag and nix.Tag functions.
1 parent 9a79c5d commit 66f4ee8

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

+nix/MultiTag.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@
9797

9898
fname = strcat(obj.alias, '::createFeature');
9999
h = nix_mx(fname, obj.nix_handle, addID, link_type);
100-
101-
r = {};
102-
if (h ~= 0)
103-
r = nix.Feature(h);
104-
end
100+
r = nix.Utils.createEntity(h, @nix.Feature);
105101
end
106102

107103
function r = has_feature(obj, id_or_name)

+nix/Tag.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@
9999

100100
fname = strcat(obj.alias, '::createFeature');
101101
h = nix_mx(fname, obj.nix_handle, addID, link_type);
102-
103-
r = {};
104-
if (h ~= 0)
105-
r = nix.Feature(h);
106-
end
102+
r = nix.Utils.createEntity(h, @nix.Feature);
107103
end
108104

109105
function r = has_feature(obj, id_or_name)

+nix/Utils.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
methods(Static)
1212

13+
function r = createEntity(handle, objConstructor)
14+
r = {};
15+
if (handle ~= 0)
16+
r = objConstructor(handle);
17+
end
18+
end
19+
1320
function r = createEntityArray(list, objConstructor)
1421
r = cell(length(list), 1);
1522
for i = 1:length(list)
@@ -33,11 +40,8 @@
3340
end
3441

3542
function r = fetchObj(nixMxFunc, handle, objConstructor)
36-
r = {};
3743
h = nix_mx(nixMxFunc, handle);
38-
if (h ~= 0)
39-
r = objConstructor(h);
40-
end
44+
r = nix.Utils.createEntity(h, objConstructor);
4145
end
4246

4347
function [] = add_entity(obj, add_this, nixEntity, mxMethod)
@@ -76,11 +80,8 @@
7680
end
7781

7882
function r = open_entity(obj, mxMethod, id_or_name, objConstructor)
79-
handle = nix_mx(mxMethod, obj.nix_handle, id_or_name);
80-
r = {};
81-
if (handle ~= 0)
82-
r = objConstructor(handle);
83-
end
83+
h = nix_mx(mxMethod, obj.nix_handle, id_or_name);
84+
r = nix.Utils.createEntity(h, objConstructor);
8485
end
8586

8687
% -----------------------------------------------------------

0 commit comments

Comments
 (0)