From 38c17f093615a16a4b4ec6dc2b5d3edb5c1d3895 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 27 Sep 2018 21:40:52 -0400 Subject: More hkutil refactoring All database access goes through hatkirby::database now. verbly::token, verbly::statement::condition, and verbly::part have been converted to use mpark::variant now. verbly::binding has been deleted, and replaced with a mpark::variant typedef in statement.h. This means that the only remaining tagged union class is verbly::generator::part. refs #5 --- lib/word.cpp | 85 ++++++++---------------------------------------------------- 1 file changed, 11 insertions(+), 74 deletions(-) (limited to 'lib/word.cpp') diff --git a/lib/word.cpp b/lib/word.cpp index 6f0fe22..60657ba 100644 --- a/lib/word.cpp +++ b/lib/word.cpp @@ -1,5 +1,4 @@ #include "word.h" -#include #include "form.h" #include "util.h" #include "database.h" @@ -45,89 +44,27 @@ namespace verbly { return field::joinThroughWhere(object::word, "lemma_id", object::form, "lemmas_forms", "form_id", "category", static_cast(category)); } - word::word(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) + word::word(const database& db, hatkirby::row row) : db_(db), valid_(true) { - id_ = sqlite3_column_int(row, 0); - notionId_ = sqlite3_column_int(row, 1); - lemmaId_ = sqlite3_column_int(row, 2); + id_ = mpark::get(row[0]); - if (sqlite3_column_type(row, 3) != SQLITE_NULL) - { - hasTagCount_ = true; - tagCount_ = sqlite3_column_int(row, 3); - } - - if (sqlite3_column_type(row, 4) != SQLITE_NULL) - { - adjectivePosition_ = static_cast(sqlite3_column_int(row, 4)); - } - - if (sqlite3_column_type(row, 5) != SQLITE_NULL) - { - hasGroup_ = true; - groupId_ = sqlite3_column_int(row, 5); - } - } - - const notion& word::getNotion() const - { - if (!valid_) - { - throw std::domain_error("Bad access to uninitialized word"); - } + notion_ = db.notions(notion::id == mpark::get(row[1])).first(); - if (!notion_.isValid()) + if (!mpark::holds_alternative(row[3])) { - notion_ = db_->notions(notion::id == notionId_).first(); - } - - return notion_; - } - - bool word::hasFrames() const - { - if (!valid_) - { - throw std::domain_error("Bad access to uninitialized word"); - } - - if (!hasGroup_) - { - return false; - } - - if (!initializedFrames_) - { - initializeFrames(); - } - - return !frames_.empty(); - } - - const std::vector& word::getFrames() const - { - if (!valid_) - { - throw std::domain_error("Bad access to uninitialized word"); + hasTagCount_ = true; + tagCount_ = mpark::get(row[3]); } - if (!hasGroup_) + if (!mpark::holds_alternative(row[4])) { - throw std::domain_error("Word does not have a group"); + adjectivePosition_ = static_cast(mpark::get(row[4])); } - if (!initializedFrames_) + if (!mpark::holds_alternative(row[5])) { - initializeFrames(); + frames_ = db.frames(*this).all(); } - - return frames_; - } - - void word::initializeFrames() const - { - initializedFrames_ = true; - frames_ = db_->frames(*this, {}, -1).all(); } const form& word::getBaseForm() const @@ -167,7 +104,7 @@ namespace verbly { void word::initializeForm(inflection infl) const { - forms_[infl] = db_->forms(form::words(infl) %= *this, verbly::form::id, -1).all(); + forms_[infl] = db_.forms(form::words(infl) %= *this, verbly::form::id, -1).all(); } filter word::synonyms_field::operator%=(filter joinCondition) const -- cgit 1.4.1