Skip to content

Commit e085558

Browse files
committed
addGroupEntity: add nix.Block group methods
1 parent bb6a8b9 commit e085558

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

+nix/Block.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,44 @@
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+
% TODO -- seems to work remove me later
27+
function g = create_group(obj, name, nixtype)
28+
handle = nix_mx('Block::createGroup', obj.nix_handle, ...
29+
name, nixtype);
30+
g = nix.Group(handle);
31+
obj.groupsCache.lastUpdate = 0;
32+
end;
33+
34+
% TODO - check if this actually works...
35+
% TODO - find better solution to deal with non-entity entries.
36+
function hasGroup = has_group(obj, group)
37+
% TODO not available from the c++ side at the moment
38+
%{
39+
if(strcmp(class(group), 'nix.Group'))
40+
hasGroup = nix_mx('Block::hasGroup', group);
41+
else
42+
error('Please provide a proper group.');
43+
end;
44+
%}
45+
end;
46+
47+
% TODO -- seems to work remove me later
48+
function delCheck = delete_group(obj, del)
49+
[delCheck, obj.groupsCache] = nix.Utils.delete_entity(obj, ...
50+
del, 'nix.Group', 'Block::deleteGroup');
51+
end;
52+
2153
% -----------------
2254
% DataArray methods
2355
% -----------------

+nix/Group.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@
2020
% DataArray methods
2121
% -----------------
2222

23+
%-- TODO seems to work -- remove me later
2324
function hasDataArray = has_data_array(obj, id_or_name)
2425
hasDataArray = nix_mx('Group::hasDataArray', ...
2526
obj.nix_handle, id_or_name);
2627
end;
27-
28+
29+
%-- TODO seems to work -- remove me later
2830
function retObj = get_data_array(obj, id_or_name)
2931
retObj = nix.Utils.open_entity(obj, ...
3032
'Group::getDataArray', id_or_name, @nix.DataArray);
3133
end;
32-
34+
35+
%-- TODO seems to work -- remove me later
3336
function [] = add_data_array(obj, add_this)
3437
obj.dataArraysCache = nix.Utils.add_entity(obj, ...
3538
add_this, 'nix.DataArray', 'Group::addDataArray', ...
3639
obj.dataArraysCache);
3740
end;
3841

42+
%-- TODO seems to work -- remove me later
3943
function delCheck = remove_data_array(obj, del)
4044
[delCheck, obj.dataArraysCache] = nix.Utils.delete_entity(obj, ...
4145
del, 'nix.DataArray', 'Group::removeDataArray', ...
@@ -46,21 +50,25 @@
4650
% Tags methods
4751
% -----------------
4852

53+
%-- TODO seems to work -- remove me later
4954
function hasTag = has_tag(obj, id_or_name)
5055
hasTag = nix_mx('Group::hasTag', obj.nix_handle, id_or_name);
5156
end;
52-
57+
58+
%-- TODO seems to work -- remove me later
5359
function retObj = get_tag(obj, id_or_name)
5460
retObj = nix.Utils.open_entity(obj, ...
5561
'Group::getTag', id_or_name, @nix.Tag);
5662
end;
57-
63+
64+
%-- TODO seems to work -- remove me later
5865
function [] = add_tag(obj, add_this)
5966
obj.tagsCache = nix.Utils.add_entity(obj, ...
6067
add_this, 'nix.Tag', 'Group::addTag', ...
6168
obj.tagsCache);
6269
end;
6370

71+
%-- TODO seems to work -- remove me later
6472
function delCheck = remove_tag(obj, del)
6573
[delCheck, obj.tagsCache] = nix.Utils.delete_entity(obj, ...
6674
del, 'nix.Tag', 'Group::removeTag', ...
@@ -71,22 +79,26 @@
7179
% MultiTag methods
7280
% -----------------
7381

82+
%-- TODO seems to work -- remove me later
7483
function hasMTag = has_multi_tag(obj, id_or_name)
7584
hasMTag = nix_mx('Group::hasMultiTag', ...
7685
obj.nix_handle, id_or_name);
7786
end;
7887

88+
%-- TODO seems to work -- remove me later
7989
function retObj = get_multi_tag(obj, id_or_name)
8090
retObj = nix.Utils.open_entity(obj, ...
8191
'Group::getMultiTag', id_or_name, @nix.MultiTag);
8292
end;
8393

94+
%-- TODO seems to work -- remove me later
8495
function [] = add_multi_tag(obj, add_this)
8596
obj.multiTagsCache = nix.Utils.add_entity(obj, ...
8697
add_this, 'nix.MultiTag', 'Group::addMultiTag', ...
8798
obj.multiTagsCache);
8899
end;
89100

101+
%-- TODO seems to work -- remove me later
90102
function delCheck = remove_multi_tag(obj, del)
91103
[delCheck, obj.multiTagsCache] = nix.Utils.delete_entity(obj, ...
92104
del, 'nix.MultiTag', 'Group::removeMultiTag', ...

nix_mx.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ void mexFunction(int nlhs,
113113
.reg("sources", &nix::Block::sources)
114114
.reg("tags", &nix::Block::tags)
115115
.reg("multiTags", &nix::Block::multiTags)
116+
.reg("groups", &nix::Block::groups)
116117
.reg("hasTag", GETBYSTR(bool, nix::Block, hasTag))
117118
.reg("hasMultiTag", GETBYSTR(bool, nix::Block, hasMultiTag))
119+
// method is only available as get by entity, not as get by id or name on the c++ side
120+
//.reg("hasGroup", GETBYSTR(bool, nix::Block, hasGroup))
118121
.reg("openDataArray", GETBYSTR(nix::DataArray, nix::Block, getDataArray))
119122
.reg("openSource", GETBYSTR(nix::Source, nix::Block, getSource))
120123
.reg("openTag", GETBYSTR(nix::Tag, nix::Block, getTag))
@@ -126,11 +129,13 @@ void mexFunction(int nlhs,
126129
.reg("deleteSource", REMOVER(nix::Source, nix::Block, deleteSource))
127130
.reg("deleteTag", REMOVER(nix::Tag, nix::Block, deleteTag))
128131
.reg("deleteMultiTag", REMOVER(nix::MultiTag, nix::Block, deleteMultiTag))
132+
.reg("deleteGroup", REMOVER(nix::Group, nix::Block, deleteGroup))
129133
.reg("set_type", SETTER(const std::string&, nix::Block, type))
130134
.reg("set_definition", SETTER(const std::string&, nix::Block, definition))
131135
.reg("set_none_definition", SETTER(const boost::none_t, nix::Block, definition));
132136
methods->add("Block::createDataArray", nixblock::create_data_array);
133137
methods->add("Block::createMultiTag", nixblock::create_multi_tag);
138+
methods->add("Block::createGroup", nixblock::create_group);
134139

135140
classdef<nix::Group>("Group", methods)
136141
.desc(&nixgroup::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

0 commit comments

Comments
 (0)