From 1fd518d1c2b1d4e88ad88218b606a284b7128107 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Oct 2017 11:19:23 -0400 Subject: Added length field to form table This commit contains a database update. --- generator/form.cpp | 4 +++- generator/form.h | 6 ++++++ generator/schema.sql | 3 ++- lib/form.cpp | 4 +++- lib/form.h | 14 +++++++++++++- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/generator/form.cpp b/generator/form.cpp index 6be9d47..f616344 100644 --- a/generator/form.cpp +++ b/generator/form.cpp @@ -14,7 +14,8 @@ namespace verbly { id_(nextId_++), text_(text), complexity_(std::count(std::begin(text), std::end(text), ' ') + 1), - proper_(std::any_of(std::begin(text), std::end(text), std::isupper)) + proper_(std::any_of(std::begin(text), std::end(text), std::isupper)), + length_(text.length()) { } @@ -32,6 +33,7 @@ namespace verbly { fields.emplace_back("form", arg.getText()); fields.emplace_back("complexity", arg.getComplexity()); fields.emplace_back("proper", arg.isProper()); + fields.emplace_back("length", arg.getLength()); db.insertIntoTable("forms", std::move(fields)); } diff --git a/generator/form.h b/generator/form.h index 5576035..5a2de30 100644 --- a/generator/form.h +++ b/generator/form.h @@ -43,6 +43,11 @@ namespace verbly { return proper_; } + int getLength() const + { + return length_; + } + std::set getPronunciations() const { return pronunciations_; @@ -56,6 +61,7 @@ namespace verbly { const std::string text_; const int complexity_; const bool proper_; + const int length_; std::set pronunciations_; diff --git a/generator/schema.sql b/generator/schema.sql index a49a853..c0f2bcb 100644 --- a/generator/schema.sql +++ b/generator/schema.sql @@ -155,7 +155,8 @@ CREATE TABLE `forms` ( `form_id` INTEGER PRIMARY KEY, `form` VARCHAR(32) NOT NULL, `complexity` SMALLINT NOT NULL, - `proper` SMALLINT NOT NULL + `proper` SMALLINT NOT NULL, + `length` SMALLINT NOT NULL ); CREATE UNIQUE INDEX `form_by_string` ON `forms`(`form`); diff --git a/lib/form.cpp b/lib/form.cpp index 2f9509f..feaf765 100644 --- a/lib/form.cpp +++ b/lib/form.cpp @@ -10,12 +10,13 @@ namespace verbly { const object form::objectType = object::form; - const std::list form::select = {"form_id", "form", "complexity", "proper"}; + const std::list form::select = {"form_id", "form", "complexity", "proper", "length"}; const field form::id = field::integerField(object::form, "form_id"); const field form::text = field::stringField(object::form, "form"); const field form::complexity = field::integerField(object::form, "complexity"); const field form::proper = field::booleanField(object::form, "proper"); + const field form::length = field::integerField(object::form, "length"); const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id"); @@ -30,6 +31,7 @@ namespace verbly { 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 diff --git a/lib/form.h b/lib/form.h index e3e1185..479672f 100644 --- a/lib/form.h +++ b/lib/form.h @@ -73,6 +73,16 @@ namespace verbly { return proper_; } + int getLength() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized form"); + } + + return length_; + } + const std::vector& getPronunciations() const; // Convenience @@ -91,6 +101,7 @@ namespace verbly { static const field text; static const field complexity; static const field proper; + static const field length; operator filter() const { @@ -123,8 +134,9 @@ namespace verbly { int id_; std::string text_; - int complexity_ ; + int complexity_; bool proper_; + int length_; const database* db_; -- cgit 1.4.1