diff options
Diffstat (limited to 'lib/selrestr.cpp')
-rw-r--r-- | lib/selrestr.cpp | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/lib/selrestr.cpp b/lib/selrestr.cpp index 74ea726..8646871 100644 --- a/lib/selrestr.cpp +++ b/lib/selrestr.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | #include "selrestr.h" | 1 | #include "selrestr.h" |
2 | 2 | ||
3 | namespace verbly { | 3 | namespace verbly { |
4 | 4 | ||
5 | selrestr::selrestr(nlohmann::json data) | 5 | selrestr::selrestr(nlohmann::json data) |
6 | { | 6 | { |
7 | if (data.find("children") != data.end()) | 7 | if (data.find("children") != data.end()) |
@@ -13,7 +13,7 @@ namespace verbly { | |||
13 | { | 13 | { |
14 | group_.children.emplace_back(child); | 14 | group_.children.emplace_back(child); |
15 | } | 15 | } |
16 | 16 | ||
17 | group_.orlogic = (data["logic"] == "or"); | 17 | group_.orlogic = (data["logic"] == "or"); |
18 | } else if (data.find("type") != data.end()) | 18 | } else if (data.find("type") != data.end()) |
19 | { | 19 | { |
@@ -24,139 +24,139 @@ namespace verbly { | |||
24 | type_ = type::empty; | 24 | type_ = type::empty; |
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | selrestr::selrestr(const selrestr& other) | 28 | selrestr::selrestr(const selrestr& other) |
29 | { | 29 | { |
30 | type_ = other.type_; | 30 | type_ = other.type_; |
31 | 31 | ||
32 | switch (type_) | 32 | switch (type_) |
33 | { | 33 | { |
34 | case type::singleton: | 34 | case type::singleton: |
35 | { | 35 | { |
36 | singleton_.pos = other.singleton_.pos; | 36 | singleton_.pos = other.singleton_.pos; |
37 | new(&singleton_.restriction) std::string(other.singleton_.restriction); | 37 | new(&singleton_.restriction) std::string(other.singleton_.restriction); |
38 | 38 | ||
39 | break; | 39 | break; |
40 | } | 40 | } |
41 | 41 | ||
42 | case type::group: | 42 | case type::group: |
43 | { | 43 | { |
44 | new(&group_.children) std::list<selrestr>(other.group_.children); | 44 | new(&group_.children) std::list<selrestr>(other.group_.children); |
45 | group_.orlogic = other.group_.orlogic; | 45 | group_.orlogic = other.group_.orlogic; |
46 | 46 | ||
47 | break; | 47 | break; |
48 | } | 48 | } |
49 | 49 | ||
50 | case type::empty: | 50 | case type::empty: |
51 | { | 51 | { |
52 | break; | 52 | break; |
53 | } | 53 | } |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | selrestr::selrestr(selrestr&& other) : selrestr() | 57 | selrestr::selrestr(selrestr&& other) : selrestr() |
58 | { | 58 | { |
59 | swap(*this, other); | 59 | swap(*this, other); |
60 | } | 60 | } |
61 | 61 | ||
62 | selrestr& selrestr::operator=(selrestr other) | 62 | selrestr& selrestr::operator=(selrestr other) |
63 | { | 63 | { |
64 | swap(*this, other); | 64 | swap(*this, other); |
65 | 65 | ||
66 | return *this; | 66 | return *this; |
67 | } | 67 | } |
68 | 68 | ||
69 | void swap(selrestr& first, selrestr& second) | 69 | void swap(selrestr& first, selrestr& second) |
70 | { | 70 | { |
71 | using type = selrestr::type; | 71 | using type = selrestr::type; |
72 | 72 | ||
73 | type tempType = first.type_; | 73 | type tempType = first.type_; |
74 | int tempPos; | 74 | int tempPos; |
75 | std::string tempRestriction; | 75 | std::string tempRestriction; |
76 | std::list<selrestr> tempChildren; | 76 | std::list<selrestr> tempChildren; |
77 | bool tempOrlogic; | 77 | bool tempOrlogic; |
78 | 78 | ||
79 | switch (tempType) | 79 | switch (tempType) |
80 | { | 80 | { |
81 | case type::singleton: | 81 | case type::singleton: |
82 | { | 82 | { |
83 | tempPos = first.singleton_.pos; | 83 | tempPos = first.singleton_.pos; |
84 | tempRestriction = std::move(first.singleton_.restriction); | 84 | tempRestriction = std::move(first.singleton_.restriction); |
85 | 85 | ||
86 | break; | 86 | break; |
87 | } | 87 | } |
88 | 88 | ||
89 | case type::group: | 89 | case type::group: |
90 | { | 90 | { |
91 | tempChildren = std::move(first.group_.children); | 91 | tempChildren = std::move(first.group_.children); |
92 | tempOrlogic = first.group_.orlogic; | 92 | tempOrlogic = first.group_.orlogic; |
93 | 93 | ||
94 | break; | 94 | break; |
95 | } | 95 | } |
96 | 96 | ||
97 | case type::empty: | 97 | case type::empty: |
98 | { | 98 | { |
99 | break; | 99 | break; |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | first.~selrestr(); | 103 | first.~selrestr(); |
104 | 104 | ||
105 | first.type_ = second.type_; | 105 | first.type_ = second.type_; |
106 | 106 | ||
107 | switch (first.type_) | 107 | switch (first.type_) |
108 | { | 108 | { |
109 | case type::singleton: | 109 | case type::singleton: |
110 | { | 110 | { |
111 | first.singleton_.pos = second.singleton_.pos; | 111 | first.singleton_.pos = second.singleton_.pos; |
112 | new(&first.singleton_.restriction) std::string(std::move(second.singleton_.restriction)); | 112 | new(&first.singleton_.restriction) std::string(std::move(second.singleton_.restriction)); |
113 | 113 | ||
114 | break; | 114 | break; |
115 | } | 115 | } |
116 | 116 | ||
117 | case type::group: | 117 | case type::group: |
118 | { | 118 | { |
119 | new(&first.group_.children) std::list<selrestr>(std::move(second.group_.children)); | 119 | new(&first.group_.children) std::list<selrestr>(std::move(second.group_.children)); |
120 | first.group_.orlogic = second.group_.orlogic; | 120 | first.group_.orlogic = second.group_.orlogic; |
121 | 121 | ||
122 | break; | 122 | break; |
123 | } | 123 | } |
124 | 124 | ||
125 | case type::empty: | 125 | case type::empty: |
126 | { | 126 | { |
127 | break; | 127 | break; |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | second.~selrestr(); | 131 | second.~selrestr(); |
132 | 132 | ||
133 | second.type_ = tempType; | 133 | second.type_ = tempType; |
134 | 134 | ||
135 | switch (second.type_) | 135 | switch (second.type_) |
136 | { | 136 | { |
137 | case type::singleton: | 137 | case type::singleton: |
138 | { | 138 | { |
139 | second.singleton_.pos = tempPos; | 139 | second.singleton_.pos = tempPos; |
140 | new(&second.singleton_.restriction) std::string(std::move(tempRestriction)); | 140 | new(&second.singleton_.restriction) std::string(std::move(tempRestriction)); |
141 | 141 | ||
142 | break; | 142 | break; |
143 | } | 143 | } |
144 | 144 | ||
145 | case type::group: | 145 | case type::group: |
146 | { | 146 | { |
147 | new(&second.group_.children) std::list<selrestr>(std::move(tempChildren)); | 147 | new(&second.group_.children) std::list<selrestr>(std::move(tempChildren)); |
148 | second.group_.orlogic = tempOrlogic; | 148 | second.group_.orlogic = tempOrlogic; |
149 | 149 | ||
150 | break; | 150 | break; |
151 | } | 151 | } |
152 | 152 | ||
153 | case type::empty: | 153 | case type::empty: |
154 | { | 154 | { |
155 | break; | 155 | break; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | selrestr::~selrestr() | 160 | selrestr::~selrestr() |
161 | { | 161 | { |
162 | switch (type_) | 162 | switch (type_) |
@@ -165,29 +165,29 @@ namespace verbly { | |||
165 | { | 165 | { |
166 | using string_type = std::string; | 166 | using string_type = std::string; |
167 | singleton_.restriction.~string_type(); | 167 | singleton_.restriction.~string_type(); |
168 | 168 | ||
169 | break; | 169 | break; |
170 | } | 170 | } |
171 | 171 | ||
172 | case type::group: | 172 | case type::group: |
173 | { | 173 | { |
174 | using list_type = std::list<selrestr>; | 174 | using list_type = std::list<selrestr>; |
175 | group_.children.~list_type(); | 175 | group_.children.~list_type(); |
176 | 176 | ||
177 | break; | 177 | break; |
178 | } | 178 | } |
179 | 179 | ||
180 | case type::empty: | 180 | case type::empty: |
181 | { | 181 | { |
182 | break; | 182 | break; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | selrestr::selrestr() : type_(type::empty) | 187 | selrestr::selrestr() : type_(type::empty) |
188 | { | 188 | { |
189 | } | 189 | } |
190 | 190 | ||
191 | selrestr::selrestr( | 191 | selrestr::selrestr( |
192 | std::string restriction, | 192 | std::string restriction, |
193 | bool pos) : | 193 | bool pos) : |
@@ -196,7 +196,7 @@ namespace verbly { | |||
196 | new(&singleton_.restriction) std::string(std::move(restriction)); | 196 | new(&singleton_.restriction) std::string(std::move(restriction)); |
197 | singleton_.pos = pos; | 197 | singleton_.pos = pos; |
198 | } | 198 | } |
199 | 199 | ||
200 | std::string selrestr::getRestriction() const | 200 | std::string selrestr::getRestriction() const |
201 | { | 201 | { |
202 | if (type_ == type::singleton) | 202 | if (type_ == type::singleton) |
@@ -206,7 +206,7 @@ namespace verbly { | |||
206 | throw std::domain_error("Only singleton selrestrs have restrictions"); | 206 | throw std::domain_error("Only singleton selrestrs have restrictions"); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | bool selrestr::getPos() const | 210 | bool selrestr::getPos() const |
211 | { | 211 | { |
212 | if (type_ == type::singleton) | 212 | if (type_ == type::singleton) |
@@ -216,7 +216,7 @@ namespace verbly { | |||
216 | throw std::domain_error("Only singleton selrestrs have positivity flags"); | 216 | throw std::domain_error("Only singleton selrestrs have positivity flags"); |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | selrestr::selrestr( | 220 | selrestr::selrestr( |
221 | std::list<selrestr> children, | 221 | std::list<selrestr> children, |
222 | bool orlogic) : | 222 | bool orlogic) : |
@@ -225,7 +225,7 @@ namespace verbly { | |||
225 | new(&group_.children) std::list<selrestr>(std::move(children)); | 225 | new(&group_.children) std::list<selrestr>(std::move(children)); |
226 | group_.orlogic = orlogic; | 226 | group_.orlogic = orlogic; |
227 | } | 227 | } |
228 | 228 | ||
229 | std::list<selrestr> selrestr::getChildren() const | 229 | std::list<selrestr> selrestr::getChildren() const |
230 | { | 230 | { |
231 | if (type_ == type::group) | 231 | if (type_ == type::group) |
@@ -235,7 +235,7 @@ namespace verbly { | |||
235 | throw std::domain_error("Only group selrestrs have children"); | 235 | throw std::domain_error("Only group selrestrs have children"); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | 238 | ||
239 | std::list<selrestr>::const_iterator selrestr::begin() const | 239 | std::list<selrestr>::const_iterator selrestr::begin() const |
240 | { | 240 | { |
241 | if (type_ == type::group) | 241 | if (type_ == type::group) |
@@ -245,7 +245,7 @@ namespace verbly { | |||
245 | throw std::domain_error("Only group selrestrs have children"); | 245 | throw std::domain_error("Only group selrestrs have children"); |
246 | } | 246 | } |
247 | } | 247 | } |
248 | 248 | ||
249 | std::list<selrestr>::const_iterator selrestr::end() const | 249 | std::list<selrestr>::const_iterator selrestr::end() const |
250 | { | 250 | { |
251 | if (type_ == type::group) | 251 | if (type_ == type::group) |
@@ -255,7 +255,7 @@ namespace verbly { | |||
255 | throw std::domain_error("Only group selrestrs have children"); | 255 | throw std::domain_error("Only group selrestrs have children"); |
256 | } | 256 | } |
257 | } | 257 | } |
258 | 258 | ||
259 | bool selrestr::getOrlogic() const | 259 | bool selrestr::getOrlogic() const |
260 | { | 260 | { |
261 | if (type_ == type::group) | 261 | if (type_ == type::group) |
@@ -265,7 +265,7 @@ namespace verbly { | |||
265 | throw std::domain_error("Only group selrestrs have logic"); | 265 | throw std::domain_error("Only group selrestrs have logic"); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | nlohmann::json selrestr::toJson() const | 269 | nlohmann::json selrestr::toJson() const |
270 | { | 270 | { |
271 | switch (type_) | 271 | switch (type_) |
@@ -274,7 +274,7 @@ namespace verbly { | |||
274 | { | 274 | { |
275 | return {}; | 275 | return {}; |
276 | } | 276 | } |
277 | 277 | ||
278 | case type::singleton: | 278 | case type::singleton: |
279 | { | 279 | { |
280 | return { | 280 | return { |
@@ -282,7 +282,7 @@ namespace verbly { | |||
282 | {"pos", singleton_.pos} | 282 | {"pos", singleton_.pos} |
283 | }; | 283 | }; |
284 | } | 284 | } |
285 | 285 | ||
286 | case type::group: | 286 | case type::group: |
287 | { | 287 | { |
288 | std::string logic; | 288 | std::string logic; |
@@ -292,12 +292,12 @@ namespace verbly { | |||
292 | } else { | 292 | } else { |
293 | logic = "and"; | 293 | logic = "and"; |
294 | } | 294 | } |
295 | 295 | ||
296 | std::list<nlohmann::json> children; | 296 | std::list<nlohmann::json> children; |
297 | std::transform(std::begin(group_.children), std::end(group_.children), std::back_inserter(children), [] (const selrestr& child) { | 297 | std::transform(std::begin(group_.children), std::end(group_.children), std::back_inserter(children), [] (const selrestr& child) { |
298 | return child.toJson(); | 298 | return child.toJson(); |
299 | }); | 299 | }); |
300 | 300 | ||
301 | return { | 301 | return { |
302 | {"logic", logic}, | 302 | {"logic", logic}, |
303 | {"children", children} | 303 | {"children", children} |