Skip to content

Commit 9bbcc56

Browse files
committed
Merge pull request #96 from mpsonntag/addGroupEntity
Add group entity LGTM
2 parents a69b9a2 + cc90ae9 commit 9bbcc56

File tree

11 files changed

+706
-2
lines changed

11 files changed

+706
-2
lines changed

+nix/Block.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,38 @@
1212
1313

1414
% assign relations
15+
nix.Dynamic.add_dyn_relation(obj, 'groups', @nix.Group);
1516
nix.Dynamic.add_dyn_relation(obj, 'dataArrays', @nix.DataArray);
1617
nix.Dynamic.add_dyn_relation(obj, 'sources', @nix.Source);
1718
nix.Dynamic.add_dyn_relation(obj, 'tags', @nix.Tag);
1819
nix.Dynamic.add_dyn_relation(obj, 'multiTags', @nix.MultiTag);
1920
end;
2021

22+
% -----------------
23+
% Group methods
24+
% -----------------
25+
26+
function g = create_group(obj, name, nixtype)
27+
handle = nix_mx('Block::createGroup', obj.nix_handle, ...
28+
name, nixtype);
29+
g = nix.Group(handle);
30+
obj.groupsCache.lastUpdate = 0;
31+
end;
32+
33+
function hasGroup = has_group(obj, id_or_name)
34+
hasGroup = nix_mx('Block::hasGroup', obj.nix_handle, id_or_name);
35+
end;
36+
37+
function retObj = get_group(obj, id_or_name)
38+
retObj = nix.Utils.open_entity(obj, ...
39+
'Block::getGroup', id_or_name, @nix.Group);
40+
end;
41+
42+
function delCheck = delete_group(obj, del)
43+
[delCheck, obj.groupsCache] = nix.Utils.delete_entity(obj, ...
44+
del, 'nix.Group', 'Block::deleteGroup');
45+
end;
46+
2147
% -----------------
2248
% DataArray methods
2349
% -----------------

+nix/Group.m

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
classdef Group < nix.NamedEntity
2+
%Group nix Group object
3+
4+
properties (Hidden)
5+
% namespace reference for nix-mx functions
6+
alias = 'Group'
7+
end
8+
9+
methods
10+
function obj = Group(h)
11+
12+
13+
% assign relations
14+
nix.Dynamic.add_dyn_relation(obj, 'dataArrays', @nix.DataArray);
15+
nix.Dynamic.add_dyn_relation(obj, 'tags', @nix.Tag);
16+
nix.Dynamic.add_dyn_relation(obj, 'multiTags', @nix.MultiTag);
17+
end;
18+
19+
% -----------------
20+
% DataArray methods
21+
% -----------------
22+
23+
function hasDataArray = has_data_array(obj, id_or_name)
24+
hasDataArray = nix_mx('Group::hasDataArray', ...
25+
obj.nix_handle, id_or_name);
26+
end;
27+
28+
function retObj = get_data_array(obj, id_or_name)
29+
retObj = nix.Utils.open_entity(obj, ...
30+
'Group::getDataArray', id_or_name, @nix.DataArray);
31+
end;
32+
33+
function [] = add_data_array(obj, add_this)
34+
obj.dataArraysCache = nix.Utils.add_entity(obj, ...
35+
add_this, 'nix.DataArray', 'Group::addDataArray', ...
36+
obj.dataArraysCache);
37+
end;
38+
39+
function delCheck = remove_data_array(obj, del)
40+
[delCheck, obj.dataArraysCache] = nix.Utils.delete_entity(obj, ...
41+
del, 'nix.DataArray', 'Group::removeDataArray', ...
42+
obj.dataArraysCache);
43+
end;
44+
45+
% -----------------
46+
% Tags methods
47+
% -----------------
48+
49+
function [] = add_tag(obj, add_this)
50+
obj.tagsCache = nix.Utils.add_entity(obj, ...
51+
add_this, 'nix.Tag', 'Group::addTag', ...
52+
obj.tagsCache);
53+
end;
54+
55+
function hasTag = has_tag(obj, id_or_name)
56+
hasTag = nix_mx('Group::hasTag', obj.nix_handle, id_or_name);
57+
end;
58+
59+
function retObj = get_tag(obj, id_or_name)
60+
retObj = nix.Utils.open_entity(obj, ...
61+
'Group::getTag', id_or_name, @nix.Tag);
62+
end;
63+
64+
function delCheck = remove_tag(obj, del)
65+
[delCheck, obj.tagsCache] = nix.Utils.delete_entity(obj, ...
66+
del, 'nix.Tag', 'Group::removeTag', ...
67+
obj.tagsCache);
68+
end;
69+
70+
% -----------------
71+
% MultiTag methods
72+
% -----------------
73+
74+
function [] = add_multi_tag(obj, add_this)
75+
obj.multiTagsCache = nix.Utils.add_entity(obj, ...
76+
add_this, 'nix.MultiTag', 'Group::addMultiTag', ...
77+
obj.multiTagsCache);
78+
end;
79+
80+
function hasMTag = has_multi_tag(obj, id_or_name)
81+
hasMTag = nix_mx('Group::hasMultiTag', ...
82+
obj.nix_handle, id_or_name);
83+
end;
84+
85+
function retObj = get_multi_tag(obj, id_or_name)
86+
retObj = nix.Utils.open_entity(obj, ...
87+
'Group::getMultiTag', id_or_name, @nix.MultiTag);
88+
end;
89+
90+
function delCheck = remove_multi_tag(obj, del)
91+
[delCheck, obj.multiTagsCache] = nix.Utils.delete_entity(obj, ...
92+
del, 'nix.MultiTag', 'Group::removeMultiTag', ...
93+
obj.multiTagsCache);
94+
end;
95+
96+
end;
97+
end

nix_mx.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "nixsection.h"
1616
#include "nixproperty.h"
1717
#include "nixblock.h"
18+
#include "nixgroup.h"
1819
#include "nixdataarray.h"
1920
#include "nixsource.h"
2021
#include "nixfeature.h"
@@ -112,8 +113,11 @@ void mexFunction(int nlhs,
112113
.reg("sources", &nix::Block::sources)
113114
.reg("tags", &nix::Block::tags)
114115
.reg("multiTags", &nix::Block::multiTags)
116+
.reg("groups", &nix::Block::groups)
115117
.reg("hasTag", GETBYSTR(bool, nix::Block, hasTag))
116118
.reg("hasMultiTag", GETBYSTR(bool, nix::Block, hasMultiTag))
119+
.reg("hasGroup", GETBYSTR(bool, nix::Block, hasGroup))
120+
.reg("getGroup", GETBYSTR(nix::Group, nix::Block, getGroup))
117121
.reg("openDataArray", GETBYSTR(nix::DataArray, nix::Block, getDataArray))
118122
.reg("openSource", GETBYSTR(nix::Source, nix::Block, getSource))
119123
.reg("openTag", GETBYSTR(nix::Tag, nix::Block, getTag))
@@ -125,11 +129,34 @@ void mexFunction(int nlhs,
125129
.reg("deleteSource", REMOVER(nix::Source, nix::Block, deleteSource))
126130
.reg("deleteTag", REMOVER(nix::Tag, nix::Block, deleteTag))
127131
.reg("deleteMultiTag", REMOVER(nix::MultiTag, nix::Block, deleteMultiTag))
132+
.reg("deleteGroup", REMOVER(nix::Group, nix::Block, deleteGroup))
128133
.reg("set_type", SETTER(const std::string&, nix::Block, type))
129134
.reg("set_definition", SETTER(const std::string&, nix::Block, definition))
130135
.reg("set_none_definition", SETTER(const boost::none_t, nix::Block, definition));
131136
methods->add("Block::createDataArray", nixblock::create_data_array);
132137
methods->add("Block::createMultiTag", nixblock::create_multi_tag);
138+
methods->add("Block::createGroup", nixblock::create_group);
139+
140+
classdef<nix::Group>("Group", methods)
141+
.desc(&nixgroup::describe)
142+
.reg("dataArrays", FILTER(std::vector<nix::DataArray>, nix::Group, , dataArrays))
143+
.reg("tags", FILTER(std::vector<nix::Tag>, nix::Group, , tags))
144+
.reg("multiTags", FILTER(std::vector<nix::MultiTag>, nix::Group, , multiTags))
145+
.reg("hasDataArray", GETBYSTR(bool, nix::Group, hasDataArray))
146+
.reg("hasTag", GETBYSTR(bool, nix::Group, hasTag))
147+
.reg("hasMultiTag", GETBYSTR(bool, nix::Group, hasMultiTag))
148+
.reg("getDataArray", GETBYSTR(nix::DataArray, nix::Group, getDataArray))
149+
.reg("getTag", GETBYSTR(nix::Tag, nix::Group, getTag))
150+
.reg("getMultiTag", GETBYSTR(nix::MultiTag, nix::Group, getMultiTag))
151+
.reg("removeDataArray", REMOVER(nix::DataArray, nix::Group, removeDataArray))
152+
.reg("removeTag", REMOVER(nix::Tag, nix::Group, removeTag))
153+
.reg("removeMultiTag", REMOVER(nix::MultiTag, nix::Group, removeMultiTag))
154+
.reg("set_type", SETTER(const std::string&, nix::Group, type))
155+
.reg("set_definition", SETTER(const std::string&, nix::Group, definition))
156+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Group, definition));
157+
methods->add("Group::addDataArray", nixgroup::add_data_array);
158+
methods->add("Group::addTag", nixgroup::add_tag);
159+
methods->add("Group::addMultiTag", nixgroup::add_multi_tag);
133160

134161
classdef<nix::DataArray>("DataArray", methods)
135162
.desc(&nixdataarray::describe)

src/nixblock.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,14 @@ namespace nixblock {
4646
output.set(0, mTag);
4747
}
4848

49+
void create_group(const extractor &input, infusor &output)
50+
{
51+
nix::Block block = input.entity<nix::Block>(1);
52+
std::string name = input.str(2);
53+
std::string type = input.str(3);
54+
55+
nix::Group group = block.createGroup(name, type);
56+
output.set(0, group);
57+
}
58+
4959
} // namespace nixblock

src/nixblock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace nixblock {
1111

1212
void create_multi_tag(const extractor &input, infusor &output);
1313

14+
void create_group(const extractor &input, infusor &output);
15+
1416
} // namespace nixblock
1517

1618
#endif

src/nixgroup.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "nixgroup.h"
2+
3+
#include "mex.h"
4+
5+
#include <nix.hpp>
6+
7+
#include "handle.h"
8+
#include "arguments.h"
9+
#include "struct.h"
10+
11+
namespace nixgroup {
12+
13+
mxArray *describe(const nix::Group &group)
14+
{
15+
struct_builder sb({ 1 }, { "id", "type", "name", "definition" });
16+
17+
sb.set(group.id());
18+
sb.set(group.type());
19+
sb.set(group.name());
20+
sb.set(group.definition());
21+
22+
return sb.array();
23+
}
24+
25+
void add_data_array(const extractor &input, infusor &output)
26+
{
27+
nix::Group currObj = input.entity<nix::Group>(1);
28+
currObj.addDataArray(input.str(2));
29+
}
30+
31+
void add_tag(const extractor &input, infusor &output)
32+
{
33+
nix::Group currObj = input.entity<nix::Group>(1);
34+
currObj.addTag(input.str(2));
35+
}
36+
37+
void add_multi_tag(const extractor &input, infusor &output)
38+
{
39+
nix::Group currObj = input.entity<nix::Group>(1);
40+
currObj.addMultiTag(input.str(2));
41+
}
42+
43+
} // namespace nixgroup

src/nixgroup.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef NIX_MX_GROUP
2+
#define NIX_MX_GROUP
3+
4+
#include "arguments.h"
5+
6+
namespace nixgroup {
7+
8+
mxArray *describe(const nix::Group &group);
9+
10+
void add_data_array(const extractor &input, infusor &output);
11+
12+
void add_tag(const extractor &input, infusor &output);
13+
14+
void add_multi_tag(const extractor &input, infusor &output);
15+
16+
} // namespace nixgroup
17+
18+
#endif

src/utils/handle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ struct entity_to_id<nix::Property> {
6363
static const int value = 8;
6464
};
6565

66+
template<>
67+
struct entity_to_id<nix::Group> {
68+
static const bool is_valid = true;
69+
static const int value = 9;
70+
};
71+
6672
/*
6773
Use value > 100 for entities that do NOT
6874
inherit from nix::Entity

tests/RunTests.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
t9.tests = TestProperty();
3434
t10.name = 'DIMENSIONS';
3535
t10.tests = TestDimensions();
36+
t11.name = 'GROUP';
37+
t11.tests = TestGroup();
3638

3739
% concatenate all test handles
38-
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10};
40+
all_tests = {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11};
3941

4042
for i = 1:length(all_tests)
4143
fprintf([10 'Execute ' all_tests{i}.name ' tests:\n\n']);
@@ -46,4 +48,3 @@
4648
end;
4749

4850
disp([10 'Tests: ' num2str(stats.okCount) ' succeeded, ' num2str(stats.errorCount) ' failed']);
49-

0 commit comments

Comments
 (0)