From f625e90a0721483f7f44b94b9bb57cc9d59565e8 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 10 Feb 2017 11:48:58 -0500 Subject: Added negative filter conversions to objects --- lib/form.h | 10 ++++++ lib/frame.h | 10 ++++++ lib/notion.h | 15 +++++++++ lib/pronunciation.h | 91 +++++++++++++++++++++++++++++++---------------------- lib/word.h | 17 ++++++++-- 5 files changed, 103 insertions(+), 40 deletions(-) (limited to 'lib') diff --git a/lib/form.h b/lib/form.h index f501ed2..e3e1185 100644 --- a/lib/form.h +++ b/lib/form.h @@ -102,6 +102,16 @@ namespace verbly { return (id == id_); } + filter operator!() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized form"); + } + + return (id != id_); + } + // Relationships to other objects static field words(inflection category); diff --git a/lib/frame.h b/lib/frame.h index dfe67c0..5fa6c6b 100644 --- a/lib/frame.h +++ b/lib/frame.h @@ -83,6 +83,16 @@ namespace verbly { return (id == id_); } + filter operator!() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized frame"); + } + + return (id != id_); + } + // Relationships to other objects static const field words; diff --git a/lib/notion.h b/lib/notion.h index 69f5cef..5388e17 100644 --- a/lib/notion.h +++ b/lib/notion.h @@ -119,9 +119,24 @@ namespace verbly { operator filter() const { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + return (id == id_); } + filter operator!() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized notion"); + } + + return (id != id_); + } + // Relationships with other objects static const field words; diff --git a/lib/pronunciation.h b/lib/pronunciation.h index 4723143..73329e4 100644 --- a/lib/pronunciation.h +++ b/lib/pronunciation.h @@ -10,128 +10,143 @@ struct sqlite3_stmt; namespace verbly { - + class form; class word; class database; - + class pronunciation { public: - + // Default constructor - + pronunciation() = default; - + // Construct from database - + pronunciation(const database& db, sqlite3_stmt* row); - + // Accessors - + bool isValid() const { return valid_; } - + int getId() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + return id_; } - + const std::vector& getPhonemes() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + return phonemes_; } - + int getSyllables() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + return syllables_; } - + std::string getStress() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + return stress_; } - + bool hasRhyme() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + return hasRhyme_; } - + std::string getPrerhyme() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + if (!hasRhyme_) { throw std::domain_error("This pronunciation has no rhyme"); } - + return prerhyme_; } - + std::string getRhyme() const { if (!valid_) { throw std::domain_error("Bad access to uninitialized pronunciation"); } - + if (!hasRhyme_) { throw std::domain_error("This pronunciation has no rhyme"); } - + return rhyme_; } - + // Type info - + static const object objectType; - + static const std::list select; - + // Query fields - + static const field id; static const field numOfSyllables; static const field stress; - + operator filter() const { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + return (id == id_); } - + + filter operator!() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + return (id != id_); + } + // Relationships to other objects - + static const field forms; // Rhyming relationship @@ -150,10 +165,10 @@ namespace verbly { }; static const rhymes_field rhymes; - + private: bool valid_ = false; - + int id_; std::vector phonemes_; int syllables_; @@ -161,14 +176,14 @@ namespace verbly { bool hasRhyme_ = false; std::string prerhyme_; std::string rhyme_; - + const database* db_; - + static const field prerhyme; static const field rhyme; - + }; - + }; #endif /* end of include guard: PRONUNCIATION_H_C68F86B0 */ diff --git a/lib/word.h b/lib/word.h index dd72c39..e866f09 100644 --- a/lib/word.h +++ b/lib/word.h @@ -105,8 +105,6 @@ namespace verbly { const std::vector
& getInflections(inflection category) const; - - // Type info static const object objectType; @@ -121,9 +119,24 @@ namespace verbly { operator filter() const { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } + return (id == id_); } + filter operator!() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } + + return (id != id_); + } + // Relationships with other objects static const field notions; -- cgit 1.4.1