diff options
Diffstat (limited to 'lib/field.h')
-rw-r--r-- | lib/field.h | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/lib/field.h b/lib/field.h index f61e038..b4bf02d 100644 --- a/lib/field.h +++ b/lib/field.h | |||
@@ -17,6 +17,7 @@ namespace verbly { | |||
17 | integer, | 17 | integer, |
18 | boolean, | 18 | boolean, |
19 | join, | 19 | join, |
20 | join_where, | ||
20 | join_through, | 21 | join_through, |
21 | hierarchal_join | 22 | hierarchal_join |
22 | }; | 23 | }; |
@@ -95,6 +96,17 @@ namespace verbly { | |||
95 | return field(obj, type::join, name, nullable, table); | 96 | return field(obj, type::join, name, nullable, table); |
96 | } | 97 | } |
97 | 98 | ||
99 | static field joinWhere( | ||
100 | object obj, | ||
101 | const char* name, | ||
102 | object joinWith, | ||
103 | const field& conditionField, | ||
104 | int conditionValue, | ||
105 | bool nullable = false) | ||
106 | { | ||
107 | return field(obj, type::join_where, name, nullable, 0, joinWith, 0, 0, 0, &conditionField, conditionValue); | ||
108 | } | ||
109 | |||
98 | static field joinThrough( | 110 | static field joinThrough( |
99 | object obj, | 111 | object obj, |
100 | const char* name, | 112 | const char* name, |
@@ -151,7 +163,10 @@ namespace verbly { | |||
151 | 163 | ||
152 | bool isJoin() const | 164 | bool isJoin() const |
153 | { | 165 | { |
154 | return ((type_ == type::join) || (type_ == type::join_through) || (type_ == type::hierarchal_join)); | 166 | return ((type_ == type::join) |
167 | || (type_ == type::join_where) | ||
168 | || (type_ == type::join_through) | ||
169 | || (type_ == type::hierarchal_join)); | ||
155 | } | 170 | } |
156 | 171 | ||
157 | const char* getColumn() const | 172 | const char* getColumn() const |
@@ -180,7 +195,7 @@ namespace verbly { | |||
180 | { | 195 | { |
181 | return (type_ == type::hierarchal_join) | 196 | return (type_ == type::hierarchal_join) |
182 | ? object_ | 197 | ? object_ |
183 | : ((type_ == type::join) || (type_ == type::join_through)) | 198 | : ((type_ == type::join) || (type_ == type::join_where) || (type_ == type::join_through)) |
184 | ? joinObject_ | 199 | ? joinObject_ |
185 | : throw std::domain_error("Non-join fields don't have join objects"); | 200 | : throw std::domain_error("Non-join fields don't have join objects"); |
186 | } | 201 | } |
@@ -209,6 +224,22 @@ namespace verbly { | |||
209 | : throw std::domain_error("Only many-to-many join fields have a foreign join column"); | 224 | : throw std::domain_error("Only many-to-many join fields have a foreign join column"); |
210 | } | 225 | } |
211 | 226 | ||
227 | // Condition joins | ||
228 | |||
229 | const field& getConditionField() const | ||
230 | { | ||
231 | return (type_ == type::join_where) | ||
232 | ? *conditionField_ | ||
233 | : throw std::domain_error("Only condition join fields have a condition field"); | ||
234 | } | ||
235 | |||
236 | int getConditionValue() const | ||
237 | { | ||
238 | return (type_ == type::join_where) | ||
239 | ? conditionValue_ | ||
240 | : throw std::domain_error("Only condition join fields have a condition value"); | ||
241 | } | ||
242 | |||
212 | // Ordering | 243 | // Ordering |
213 | 244 | ||
214 | bool operator<(const field& other) const | 245 | bool operator<(const field& other) const |
@@ -217,20 +248,30 @@ namespace verbly { | |||
217 | // However, there do exist a number of relationships from an object to | 248 | // However, there do exist a number of relationships from an object to |
218 | // itself, such as notion hypernymy/hyponymy. Hypernymy and hyponymy have | 249 | // itself, such as notion hypernymy/hyponymy. Hypernymy and hyponymy have |
219 | // the same object (notion), the same column (notion_id), and the same | 250 | // the same object (notion), the same column (notion_id), and the same |
220 | // table (hypernymy); however, they have different join columns. | 251 | // table (hypernymy); however, they have different join columns. For |
221 | return std::tie(object_, column_, table_, joinColumn_) < std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | 252 | // condition joins, the condition field and condition value are also |
253 | // significant. | ||
254 | if (conditionField_) | ||
255 | { | ||
256 | return std::tie(object_, column_, table_, joinColumn_, *conditionField_, conditionValue_) | ||
257 | < std::tie(other.object_, other.column_, other.table_, other.joinColumn_, *other.conditionField_, other.conditionValue_); | ||
258 | } else { | ||
259 | return std::tie(object_, column_, table_, joinColumn_) < std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | ||
260 | } | ||
222 | } | 261 | } |
223 | 262 | ||
224 | // Equality | 263 | // Equality |
225 | 264 | ||
226 | bool operator==(const field& other) const | 265 | bool operator==(const field& other) const |
227 | { | 266 | { |
228 | // For the most part, (object, column) uniquely identifies fields. | 267 | // See operator<() for documentation. |
229 | // However, there do exist a number of relationships from an object to | 268 | if (conditionField_) |
230 | // itself, such as notion hypernymy/hyponymy. Hypernymy and hyponymy have | 269 | { |
231 | // the same object (notion), the same column (notion_id), and the same | 270 | return std::tie(object_, column_, table_, joinColumn_, *conditionField_, conditionValue_) |
232 | // table (hypernymy); however, they have different join columns. | 271 | == std::tie(other.object_, other.column_, other.table_, other.joinColumn_, *other.conditionField_, other.conditionValue_); |
233 | return std::tie(object_, column_, table_, joinColumn_) == std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | 272 | } else { |
273 | return std::tie(object_, column_, table_, joinColumn_) == std::tie(other.object_, other.column_, other.table_, other.joinColumn_); | ||
274 | } | ||
234 | } | 275 | } |
235 | 276 | ||
236 | // Filter construction | 277 | // Filter construction |
@@ -245,6 +286,7 @@ namespace verbly { | |||
245 | filter operator==(part_of_speech value) const; // Part of speech equality | 286 | filter operator==(part_of_speech value) const; // Part of speech equality |
246 | filter operator==(positioning value) const; // Adjective positioning equality | 287 | filter operator==(positioning value) const; // Adjective positioning equality |
247 | filter operator==(inflection value) const; // Inflection category equality | 288 | filter operator==(inflection value) const; // Inflection category equality |
289 | filter operator==(part_type value) const; // Verb frame part type equality | ||
248 | 290 | ||
249 | filter operator==(bool value) const; // Boolean equality | 291 | filter operator==(bool value) const; // Boolean equality |
250 | 292 | ||
@@ -252,6 +294,10 @@ namespace verbly { | |||
252 | filter operator!=(std::string value) const; // String inequality | 294 | filter operator!=(std::string value) const; // String inequality |
253 | filter operator%=(std::string value) const; // String matching | 295 | filter operator%=(std::string value) const; // String matching |
254 | 296 | ||
297 | filter operator==(const char* value) const; // String equality | ||
298 | filter operator!=(const char* value) const; // String inequality | ||
299 | filter operator%=(const char* value) const; // String matching | ||
300 | |||
255 | operator filter() const; // Non-nullity | 301 | operator filter() const; // Non-nullity |
256 | filter operator!() const; // Nullity | 302 | filter operator!() const; // Nullity |
257 | 303 | ||
@@ -270,7 +316,9 @@ namespace verbly { | |||
270 | object joinObject = object::undefined, | 316 | object joinObject = object::undefined, |
271 | const char* foreignColumn = 0, | 317 | const char* foreignColumn = 0, |
272 | const char* joinColumn = 0, | 318 | const char* joinColumn = 0, |
273 | const char* foreignJoinColumn = 0) : | 319 | const char* foreignJoinColumn = 0, |
320 | const field* conditionField = 0, | ||
321 | int conditionValue = 0) : | ||
274 | object_(obj), | 322 | object_(obj), |
275 | type_(datatype), | 323 | type_(datatype), |
276 | column_(column), | 324 | column_(column), |
@@ -279,7 +327,9 @@ namespace verbly { | |||
279 | joinObject_(joinObject), | 327 | joinObject_(joinObject), |
280 | foreignColumn_(foreignColumn), | 328 | foreignColumn_(foreignColumn), |
281 | joinColumn_(joinColumn), | 329 | joinColumn_(joinColumn), |
282 | foreignJoinColumn_(foreignJoinColumn) | 330 | foreignJoinColumn_(foreignJoinColumn), |
331 | conditionField_(conditionField), | ||
332 | conditionValue_(conditionValue) | ||
283 | { | 333 | { |
284 | } | 334 | } |
285 | 335 | ||
@@ -300,6 +350,10 @@ namespace verbly { | |||
300 | const char* joinColumn_ = 0; | 350 | const char* joinColumn_ = 0; |
301 | const char* foreignJoinColumn_ = 0; | 351 | const char* foreignJoinColumn_ = 0; |
302 | 352 | ||
353 | // Condition joins | ||
354 | const field* conditionField_ = 0; | ||
355 | int conditionValue_ = 0; | ||
356 | |||
303 | }; | 357 | }; |
304 | 358 | ||
305 | }; | 359 | }; |