diff options
Diffstat (limited to 'lib/form.cpp')
| -rw-r--r-- | lib/form.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
| diff --git a/lib/form.cpp b/lib/form.cpp new file mode 100644 index 0000000..8ba3bd7 --- /dev/null +++ b/lib/form.cpp | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #include "form.h" | ||
| 2 | #include <sqlite3.h> | ||
| 3 | #include "filter.h" | ||
| 4 | #include "pronunciation.h" | ||
| 5 | #include "database.h" | ||
| 6 | #include "query.h" | ||
| 7 | |||
| 8 | namespace verbly { | ||
| 9 | |||
| 10 | const object form::objectType = object::form; | ||
| 11 | |||
| 12 | const std::list<std::string> form::select = {"form_id", "form", "complexity", "proper"}; | ||
| 13 | |||
| 14 | const field form::id = field::integerField(object::form, "form_id"); | ||
| 15 | const field form::text = field::stringField(object::form, "form"); | ||
| 16 | const field form::complexity = field::integerField(object::form, "complexity"); | ||
| 17 | const field form::proper = field::booleanField(object::form, "proper"); | ||
| 18 | |||
| 19 | const field form::pronunciation = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id"); | ||
| 20 | |||
| 21 | const field form::lemmaJoin = field::joinField(object::form, "form_id", object::lemma); | ||
| 22 | const field form::inflectionCategory = field::integerField("lemmas_forms", "category"); | ||
| 23 | |||
| 24 | form::form(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) | ||
| 25 | { | ||
| 26 | id_ = sqlite3_column_int(row, 0); | ||
| 27 | text_ = std::string(reinterpret_cast<const char*>(sqlite3_column_text(row, 1))); | ||
| 28 | complexity_ = sqlite3_column_int(row, 2); | ||
| 29 | proper_ = (sqlite3_column_int(row, 3) == 1); | ||
| 30 | } | ||
| 31 | |||
| 32 | filter operator%=(form::inflection_field check, filter joinCondition) | ||
| 33 | { | ||
| 34 | return (form::lemmaJoin %= (joinCondition && (form::inflectionCategory == check.getCategory()))); | ||
| 35 | } | ||
| 36 | |||
| 37 | const std::vector<pronunciation>& form::getPronunciations() const | ||
| 38 | { | ||
| 39 | if (!valid_) | ||
| 40 | { | ||
| 41 | throw std::domain_error("Bad access to uninitialized form"); | ||
| 42 | } | ||
| 43 | |||
| 44 | if (!initializedPronunciations_) | ||
| 45 | { | ||
| 46 | pronunciations_ = db_->pronunciations(pronunciation::form %= *this, false, -1).all(); | ||
| 47 | initializedPronunciations_ = true; | ||
| 48 | } | ||
| 49 | |||
| 50 | return pronunciations_; | ||
| 51 | } | ||
| 52 | |||
| 53 | }; | ||
