Skip to content

Commit b27b585

Browse files
committed
util open entity methods
1 parent 326e7aa commit b27b585

File tree

7 files changed

+36
-70
lines changed

7 files changed

+36
-70
lines changed

+nix/Block.m

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@
2828
% -----------------
2929

3030
function retObj = data_array(obj, id_or_name)
31-
handle = nix_mx('Block::openDataArray', obj.nix_handle, id_or_name);
32-
retObj = {};
33-
if handle ~= 0
34-
retObj = nix.DataArray(handle);
35-
end;
31+
retObj = nix.Utils.open_entity(obj, ...
32+
'Block::openDataArray', id_or_name, @nix.DataArray);
3633
end;
3734

3835
function da = create_data_array(obj, name, nixtype, dtype, shape)
@@ -65,11 +62,8 @@
6562
end;
6663

6764
function retObj = open_source(obj, id_or_name)
68-
handle = nix_mx('Block::openSource', obj.nix_handle, id_or_name);
69-
retObj = {};
70-
if handle ~= 0
71-
retObj = nix.Source(handle);
72-
end;
65+
retObj = nix.Utils.open_entity(obj, ...
66+
'Block::openSource', id_or_name, @nix.Source);
7367
end;
7468

7569
% -----------------
@@ -81,11 +75,8 @@
8175
end;
8276

8377
function retObj = open_tag(obj, id_or_name)
84-
handle = nix_mx('Block::openTag', obj.nix_handle, id_or_name);
85-
retObj = {};
86-
if handle ~= 0
87-
retObj = nix.Tag(handle);
88-
end;
78+
retObj = nix.Utils.open_entity(obj, ...
79+
'Block::openTag', id_or_name, @nix.Tag);
8980
end;
9081

9182
function tag = create_tag(obj, name, type, position)
@@ -104,11 +95,8 @@
10495
end;
10596

10697
function retObj = open_multi_tag(obj, id_or_name)
107-
handle = nix_mx('Block::openMultiTag', obj.nix_handle, id_or_name);
108-
retObj = {};
109-
if handle ~= 0
110-
retObj = nix.MultiTag(handle);
111-
end;
98+
retObj = nix.Utils.open_entity(obj, ...
99+
'Block::openMultiTag', id_or_name, @nix.MultiTag);
112100
end;
113101

114102
% -----------------

+nix/File.m

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333
% ----------------
3434

3535
function retObj = openBlock(obj, id_or_name)
36-
handle = nix_mx('File::openBlock', obj.nix_handle, id_or_name);
37-
retObj = {};
38-
if handle ~= 0
39-
retObj = nix.Block(handle);
40-
end;
36+
retObj = nix.Utils.open_entity(obj, ...
37+
'File::openBlock', id_or_name, @nix.Block);
4138
end
4239

4340
function blocks = get.blocks(obj)
@@ -60,11 +57,8 @@
6057
% ----------------
6158

6259
function retObj = openSection(obj, id_or_name)
63-
handle = nix_mx('File::openSection', obj.nix_handle, id_or_name);
64-
retObj = {};
65-
if handle ~= 0
66-
retObj = nix.Section(handle);
67-
end;
60+
retObj = nix.Utils.open_entity(obj, ...
61+
'File::openSection', id_or_name, @nix.Section);
6862
end
6963

7064
function sections = get.sections(obj)

+nix/MultiTag.m

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,8 @@
7676
% ------------------
7777

7878
function retObj = open_reference(obj, id_or_name)
79-
handle = nix_mx('MultiTag::openReferences', obj.nix_handle, id_or_name);
80-
retObj = {};
81-
if handle ~= 0
82-
retObj = nix.DataArray(handle);
83-
end;
79+
retObj = nix.Utils.open_entity(obj, ...
80+
'MultiTag::openReferences', id_or_name, @nix.DataArray);
8481
end;
8582

8683
function da = get.references(obj)
@@ -105,11 +102,8 @@
105102
% ------------------
106103

107104
function retObj = open_feature(obj, id_or_name)
108-
handle = nix_mx('MultiTag::openFeature', obj.nix_handle, id_or_name);
109-
retObj = {};
110-
if handle ~= 0
111-
retObj = nix.Feature(handle);
112-
end;
105+
retObj = nix.Utils.open_entity(obj, ...
106+
'MultiTag::openFeature', id_or_name, @nix.Feature);
113107
end;
114108

115109
function feat = get.features(obj)
@@ -134,11 +128,8 @@
134128
% ------------------
135129

136130
function retObj = open_source(obj, id_or_name)
137-
handle = nix_mx('MultiTag::openSource', obj.nix_handle, id_or_name);
138-
retObj = {};
139-
if handle ~= 0
140-
retObj = nix.Source(handle);
141-
end;
131+
retObj = nix.Utils.open_entity(obj, ...
132+
'MultiTag::openSource', id_or_name, @nix.Source);
142133
end;
143134

144135
function sources = get.sources(obj)

+nix/Section.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@
5151
% ----------------
5252

5353
function retObj = open_section(obj, id_or_name)
54-
handle = nix_mx('Section::openSection', obj.nix_handle, id_or_name);
55-
retObj = {};
56-
if handle ~= 0
57-
retObj = nix.Section(handle);
58-
end;
54+
retObj = nix.Utils.open_entity(obj, ...
55+
'Section::openSection', id_or_name, @nix.Section);
5956
end;
6057

6158
function hs = has_section(obj, id_or_name)

+nix/Source.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@
6363
end;
6464

6565
function retObj = open_source(obj, id_or_name)
66-
handle = nix_mx('Source::openSource', obj.nix_handle, id_or_name);
67-
retObj = {};
68-
if handle ~= 0
69-
retObj = nix.Source(handle);
70-
end;
66+
retObj = nix.Utils.open_entity(obj, ...
67+
'Source::openSource', id_or_name, @nix.Source);
7168
end;
7269

7370
function sources = get.sources(obj)

+nix/Tag.m

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,8 @@
9696
end;
9797

9898
function retObj = open_reference(obj, id_or_name)
99-
handle = nix_mx('Tag::openReferenceDataArray', obj.nix_handle, id_or_name);
100-
retObj = {};
101-
if handle ~= 0
102-
retObj = nix.DataArray(handle);
103-
end;
99+
retObj = nix.Utils.open_entity(obj, ...
100+
'Tag::openReferenceDataArray', id_or_name, @nix.DataArray);
104101
end;
105102

106103
function da = get.references(obj)
@@ -123,11 +120,8 @@
123120
% ------------------
124121

125122
function retObj = open_feature(obj, id_or_name)
126-
handle = nix_mx('Tag::openFeature', obj.nix_handle, id_or_name);
127-
retObj = {};
128-
if handle ~= 0
129-
retObj = nix.Feature(handle);
130-
end;
123+
retObj = nix.Utils.open_entity(obj, ...
124+
'Tag::openFeature', id_or_name, @nix.Feature);
131125
end;
132126

133127
function feat = get.features(obj)
@@ -160,11 +154,8 @@
160154
end;
161155

162156
function retObj = open_source(obj, id_or_name)
163-
handle = nix_mx('Tag::openSource', obj.nix_handle, id_or_name);
164-
retObj = {};
165-
if handle ~= 0
166-
retObj = nix.Source(handle);
167-
end;
157+
retObj = nix.Utils.open_entity(obj, ...
158+
'Tag::openSource', id_or_name, @nix.Source);
168159
end;
169160

170161
function sources = get.sources(obj)

+nix/Utils.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
delCheck = nix_mx(mxMethod, obj.nix_handle, delID);
5757
currCache.lastUpdate = 0;
5858
end;
59+
60+
function retObj = open_entity(obj, mxMethod, id_or_name, objConstructor)
61+
handle = nix_mx(mxMethod, obj.nix_handle, id_or_name);
62+
retObj = {};
63+
if handle ~= 0
64+
retObj = objConstructor(handle);
65+
end;
66+
end;
5967
end;
6068
end
6169

0 commit comments

Comments
 (0)