Skip to content

Commit dba0f2c

Browse files
committed
migrateToGlue: refactor Section entity
1 parent 4f9b5c8 commit dba0f2c

File tree

5 files changed

+16
-40
lines changed

5 files changed

+16
-40
lines changed

+nix/Section.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@
8282
'Section::sections', obj.nix_handle, obj.sectionsCache, @nix.Section);
8383
end
8484

85-
function section = open_section(obj, id_or_name)
86-
sh = nix_mx('Section::openSection', obj.nix_handle, id_or_name);
87-
section = nix.Section(sh);
85+
function retObj = open_section(obj, id_or_name)
86+
handle = nix_mx('Section::openSection', obj.nix_handle, id_or_name);
87+
retObj = {};
88+
if handle ~= 0
89+
retObj = nix.Section(handle);
90+
end;
8891
end;
8992

9093
function hs = has_section(obj, id_or_name)

nix_mx.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,8 @@ const std::vector<fendpoint> funcs = {
115115

116116
// Section
117117
{ "Section::describe", nixsection::describe },
118-
{ "Section::link", nixsection::link },
119-
{ "Section::parent", nixsection::parent },
120118
{ "Section::hasSection", nixsection::has_section },
121-
{ "Section::openSection", nixsection::open_section },
122119
{ "Section::listSections", nixsection::list_sections },
123-
{ "Section::sections", nixsection::sections },
124120
{ "Section::hasProperty", nixsection::has_property },
125121
{ "Section::listProperties", nixsection::list_properties }
126122
};
@@ -208,6 +204,12 @@ void mexFunction(int nlhs,
208204
.reg("openFeature", GETBYSTR(nix::Feature, nix::MultiTag, getFeature))
209205
.reg("openSource", GETBYSTR(nix::Source, nix::MultiTag, getSource));
210206

207+
classdef<nix::Section>("Section", methods)
208+
.reg("sections", &nix::Section::sections)
209+
.reg("openSection", GETBYSTR(nix::Section, nix::Section, getSection))
210+
.reg("link", GETCONTENT(nix::Section, nix::Section, link))
211+
.reg("parent", GETCONTENT(nix::Section, nix::Section, parent));
212+
211213
mexAtExit(on_exit);
212214
});
213215

src/nixsection.cc

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,12 @@ void describe(const extractor &input, infusor &output)
2929
output.set(0, sb.array());
3030
}
3131

32-
void link(const extractor &input, infusor &output)
33-
{
34-
nix::Section section = input.entity<nix::Section>(1);
35-
output.set(0, nixgen::get_handle_or_none(section.link()));
36-
}
37-
38-
void parent(const extractor &input, infusor &output)
39-
{
40-
nix::Section section = input.entity<nix::Section>(1);
41-
output.set(0, nixgen::get_handle_or_none(section.parent()));
42-
}
43-
4432
void has_section(const extractor &input, infusor &output)
4533
{
4634
nix::Section section = input.entity<nix::Section>(1);
4735
output.set(0, nixgen::has_entity(section.hasSection(input.str(2)), { "hasSection" }));
4836
}
4937

50-
void open_section(const extractor &input, infusor &output)
51-
{
52-
nix::Section section = input.entity<nix::Section>(1);
53-
nix::Section sec = section.getSection(input.str(2));
54-
handle h = handle(sec);
55-
output.set(0, h);
56-
}
57-
5838
void list_sections(const extractor &input, infusor &output)
5939
{
6040
nix::Section section = input.entity<nix::Section>(1);
@@ -73,13 +53,6 @@ void list_sections(const extractor &input, infusor &output)
7353
output.set(0, sb.array());
7454
}
7555

76-
void sections(const extractor &input, infusor &output)
77-
{
78-
nix::Section section = input.entity<nix::Section>(1);
79-
std::vector<nix::Section> sections = section.sections();
80-
output.set(0, sections);
81-
}
82-
8356
void has_property(const extractor &input, infusor &output)
8457
{
8558
nix::Section section = input.entity<nix::Section>(1);

src/nixsection.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@ namespace nixsection {
77

88
void describe(const extractor &input, infusor &output);
99

10-
void link(const extractor &input, infusor &output);
11-
12-
void parent(const extractor &input, infusor &output);
13-
1410
void has_section(const extractor &input, infusor &output);
1511

1612
void open_section(const extractor &input, infusor &output);
1713

1814
void list_sections(const extractor &input, infusor &output);
1915

20-
void sections(const extractor &input, infusor &output);
21-
2216
void has_property(const extractor &input, infusor &output);
2317

2418
void list_properties(const extractor &input, infusor &output);

tests/TestSection.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
name = s1.sections{1}.name;
3333
s2 = s1.open_section(name);
3434
assert(strcmp(s2.id, s1.sections{1}.id));
35+
36+
%-- test open non existing section
37+
getSection = s1.open_section('I dont exist');
38+
assert(isempty(getSection));
3539
end
3640

3741
function [] = test_parent( varargin )

0 commit comments

Comments
 (0)