summary refs log tree commit diff stats
path: root/generator/group.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/group.cpp')
-rw-r--r--generator/group.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/generator/group.cpp b/generator/group.cpp index 334c2aa..cebe2b9 100644 --- a/generator/group.cpp +++ b/generator/group.cpp
@@ -8,37 +8,37 @@
8 8
9namespace verbly { 9namespace verbly {
10 namespace generator { 10 namespace generator {
11 11
12 int group::nextId_ = 0; 12 int group::nextId_ = 0;
13 13
14 group::group() : id_(nextId_++) 14 group::group() : id_(nextId_++)
15 { 15 {
16 } 16 }
17 17
18 void group::setParent(const group& parent) 18 void group::setParent(const group& parent)
19 { 19 {
20 // Adding a group to itself is nonsensical. 20 // Adding a group to itself is nonsensical.
21 assert(&parent != this); 21 assert(&parent != this);
22 22
23 parent_ = &parent; 23 parent_ = &parent;
24 } 24 }
25 25
26 void group::addRole(role r) 26 void group::addRole(role r)
27 { 27 {
28 std::string name = r.getName(); 28 std::string name = r.getName();
29 roles_[name] = std::move(r); 29 roles_[name] = std::move(r);
30 roleNames_.insert(std::move(name)); 30 roleNames_.insert(std::move(name));
31 } 31 }
32 32
33 void group::addFrame(const frame& f) 33 void group::addFrame(const frame& f)
34 { 34 {
35 frames_.insert(&f); 35 frames_.insert(&f);
36 } 36 }
37 37
38 std::set<std::string> group::getRoles() const 38 std::set<std::string> group::getRoles() const
39 { 39 {
40 std::set<std::string> fullRoles = roleNames_; 40 std::set<std::string> fullRoles = roleNames_;
41 41
42 if (hasParent()) 42 if (hasParent())
43 { 43 {
44 for (std::string name : getParent().getRoles()) 44 for (std::string name : getParent().getRoles())
@@ -46,10 +46,10 @@ namespace verbly {
46 fullRoles.insert(name); 46 fullRoles.insert(name);
47 } 47 }
48 } 48 }
49 49
50 return fullRoles; 50 return fullRoles;
51 } 51 }
52 52
53 const role& group::getRole(std::string name) const 53 const role& group::getRole(std::string name) const
54 { 54 {
55 if (roles_.count(name)) 55 if (roles_.count(name))
@@ -62,11 +62,11 @@ namespace verbly {
62 throw std::invalid_argument("Specified role not found in verb group"); 62 throw std::invalid_argument("Specified role not found in verb group");
63 } 63 }
64 } 64 }
65 65
66 std::set<const frame*> group::getFrames() const 66 std::set<const frame*> group::getFrames() const
67 { 67 {
68 std::set<const frame*> fullFrames = frames_; 68 std::set<const frame*> fullFrames = frames_;
69 69
70 if (hasParent()) 70 if (hasParent())
71 { 71 {
72 for (const frame* f : getParent().getFrames()) 72 for (const frame* f : getParent().getFrames())
@@ -74,47 +74,47 @@ namespace verbly {
74 fullFrames.insert(f); 74 fullFrames.insert(f);
75 } 75 }
76 } 76 }
77 77
78 return fullFrames; 78 return fullFrames;
79 } 79 }
80 80
81 database& operator<<(database& db, const group& arg) 81 database& operator<<(database& db, const group& arg)
82 { 82 {
83 // Serialize the group first 83 // Serialize the group first
84 { 84 {
85 std::list<field> fields; 85 std::list<field> fields;
86 fields.emplace_back("group_id", arg.getId()); 86 fields.emplace_back("group_id", arg.getId());
87 87
88 nlohmann::json jsonRoles; 88 nlohmann::json jsonRoles;
89 for (std::string name : arg.getRoles()) 89 for (std::string name : arg.getRoles())
90 { 90 {
91 const role& r = arg.getRole(name); 91 const role& r = arg.getRole(name);
92 92
93 nlohmann::json jsonRole; 93 nlohmann::json jsonRole;
94 jsonRole["type"] = name; 94 jsonRole["type"] = name;
95 jsonRole["selrestrs"] = r.getSelrestrs().toJson(); 95 jsonRole["selrestrs"] = r.getSelrestrs().toJson();
96 96
97 jsonRoles.emplace_back(std::move(jsonRole)); 97 jsonRoles.emplace_back(std::move(jsonRole));
98 } 98 }
99 99
100 fields.emplace_back("data", jsonRoles.dump()); 100 fields.emplace_back("data", jsonRoles.dump());
101 101
102 db.insertIntoTable("groups", std::move(fields)); 102 db.insertIntoTable("groups", std::move(fields));
103 } 103 }
104 104
105 // Then, serialize the group/frame relationship 105 // Then, serialize the group/frame relationship
106 for (const frame* f : arg.getFrames()) 106 for (const frame* f : arg.getFrames())
107 { 107 {
108 std::list<field> fields; 108 std::list<field> fields;
109 109
110 fields.emplace_back("group_id", arg.getId()); 110 fields.emplace_back("group_id", arg.getId());
111 fields.emplace_back("frame_id", f->getId()); 111 fields.emplace_back("frame_id", f->getId());
112 112
113 db.insertIntoTable("groups_frames", std::move(fields)); 113 db.insertIntoTable("groups_frames", std::move(fields));
114 } 114 }
115 115
116 return db; 116 return db;
117 } 117 }
118 118
119 }; 119 };
120}; 120};