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/form.cpp | 52 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'lib/form.cpp') diff --git a/lib/form.cpp b/lib/form.cpp index b2c424d..4983274 100644 --- a/lib/form.cpp +++ b/lib/form.cpp @@ -1,5 +1,4 @@ #include "form.h" -#include #include #include "filter.h" #include "database.h" @@ -24,29 +23,15 @@ namespace verbly { return field::joinThroughWhere(object::form, "form_id", object::word, "lemmas_forms", "lemma_id", "category", static_cast(category)); } - form::form(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) + form::form(const database& db, hatkirby::row row) : valid_(true) { - id_ = sqlite3_column_int(row, 0); - text_ = std::string(reinterpret_cast(sqlite3_column_text(row, 1))); - complexity_ = sqlite3_column_int(row, 2); - proper_ = (sqlite3_column_int(row, 3) == 1); - length_ = sqlite3_column_int(row, 4); - } - - const std::vector& form::getPronunciations() const - { - if (!valid_) - { - throw std::domain_error("Bad access to uninitialized form"); - } - - if (!initializedPronunciations_) - { - pronunciations_ = db_->pronunciations(pronunciation::forms %= *this, pronunciation::id, -1).all(); - initializedPronunciations_ = true; - } + id_ = mpark::get(row[0]); + text_ = mpark::get(row[1]); + complexity_ = mpark::get(row[2]); + proper_ = (mpark::get(row[3]) == 1); + length_ = mpark::get(row[4]); - return pronunciations_; + pronunciations_ = db.pronunciations(*this, pronunciation::id, -1).all(); } bool form::startsWithVowelSound() const @@ -56,17 +41,24 @@ namespace verbly { throw std::domain_error("Bad access to uninitialized form"); } - const std::vector& pronunciations = getPronunciations(); - if (!pronunciations.empty()) + if (!pronunciations_.empty()) { - return std::any_of(std::begin(pronunciations), std::end(pronunciations), [] (const pronunciation& p) { - return p.getPhonemes().front().find_first_of("012") != std::string::npos; - }); + return std::any_of( + std::begin(pronunciations_), + std::end(pronunciations_), + [] (const pronunciation& p) { + return p.getPhonemes().front().find_first_of("012") != + std::string::npos; + }); } else { - // If the word is not in CMUDICT, fall back to checking whether the first letter is a vowel. - // Not perfect but will work in most cases. + // If the word is not in CMUDICT, fall back to checking whether the first + // letter is a vowel. Not perfect but will work in most cases. char ch = std::tolower(text_.front()); - return (ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u'); + return (ch == 'a') || + (ch == 'e') || + (ch == 'i') || + (ch == 'o') || + (ch == 'u'); } } -- cgit 1.4.1