Skip to content

Commit 035269d

Browse files
committed
addGroupEntity: add group entity I
1 parent a69b9a2 commit 035269d

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

nix_mx.cc

Lines changed: 34 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"
@@ -131,6 +132,39 @@ void mexFunction(int nlhs,
131132
methods->add("Block::createDataArray", nixblock::create_data_array);
132133
methods->add("Block::createMultiTag", nixblock::create_multi_tag);
133134

135+
classdef<nix::Group>("Group", methods)
136+
.desc(&nixgroup::describe)
137+
// does not work
138+
//.reg("dataArrays", &nix::Group::dataArrays)
139+
// does not work
140+
//.reg("tags", &nix::Group::tags)
141+
// does not work
142+
//.reg("multiTags", &nix::Group::multiTags)
143+
// compiles, should work
144+
.reg("hasDataArray", GETBYSTR(bool, nix::Group, hasDataArray))
145+
// compiles, should work
146+
.reg("hasTag", GETBYSTR(bool, nix::Group, hasTag))
147+
// compiles, should work
148+
.reg("hasMultiTag", GETBYSTR(bool, nix::Group, hasMultiTag))
149+
// compiles, should work
150+
.reg("openDataArray", GETBYSTR(nix::DataArray, nix::Group, getDataArray))
151+
// compiles, should work
152+
.reg("openTag", GETBYSTR(nix::Tag, nix::Group, getTag))
153+
// compiles, should work
154+
.reg("openMultiTag", GETBYSTR(nix::MultiTag, nix::Group, getMultiTag))
155+
// compiles, should work
156+
.reg("deleteDataArray", REMOVER(nix::DataArray, nix::Group, removeDataArray))
157+
// compiles, should work, deleteTag in Block
158+
.reg("deleteTag", REMOVER(nix::Tag, nix::Group, removeTag))
159+
// should work, deleteMultiTag in Block
160+
.reg("deleteMultiTag", REMOVER(nix::MultiTag, nix::Group, removeMultiTag))
161+
.reg("set_type", SETTER(const std::string&, nix::Group, type))
162+
.reg("set_definition", SETTER(const std::string&, nix::Group, definition))
163+
.reg("set_none_definition", SETTER(const boost::none_t, nix::Group, definition));
164+
methods->add("Group::addDataArray", nixgroup::add_data_array);
165+
methods->add("Group::addTag", nixgroup::add_tag);
166+
methods->add("Group::addMultiTag", nixgroup::add_multi_tag);
167+
134168
classdef<nix::DataArray>("DataArray", methods)
135169
.desc(&nixdataarray::describe)
136170
.reg("sources", IDATAARRAY(std::vector<nix::Source>, EntityWithSources, std::function<bool(const nix::Source &)>, sources, const))

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

0 commit comments

Comments
 (0)