diff options
Diffstat (limited to 'lib/form.h')
| -rw-r--r-- | lib/form.h | 149 |
1 files changed, 149 insertions, 0 deletions
| diff --git a/lib/form.h b/lib/form.h new file mode 100644 index 0000000..c6a1353 --- /dev/null +++ b/lib/form.h | |||
| @@ -0,0 +1,149 @@ | |||
| 1 | #ifndef FORM_H_3A6C962C | ||
| 2 | #define FORM_H_3A6C962C | ||
| 3 | |||
| 4 | #include <list> | ||
| 5 | #include <vector> | ||
| 6 | #include <string> | ||
| 7 | #include <stdexcept> | ||
| 8 | #include "field.h" | ||
| 9 | #include "filter.h" | ||
| 10 | |||
| 11 | struct sqlite3_stmt; | ||
| 12 | |||
| 13 | namespace verbly { | ||
| 14 | |||
| 15 | class pronunciation; | ||
| 16 | class database; | ||
| 17 | |||
| 18 | class form { | ||
| 19 | public: | ||
| 20 | |||
| 21 | // Default constructor | ||
| 22 | |||
| 23 | form() = default; | ||
| 24 | |||
| 25 | // Construct from database | ||
| 26 | |||
| 27 | form(const database& db, sqlite3_stmt* row); | ||
| 28 | |||
| 29 | // Accessors | ||
| 30 | |||
| 31 | operator bool() const | ||
| 32 | { | ||
| 33 | return valid_; | ||
| 34 | } | ||
| 35 | |||
| 36 | int getId() const | ||
| 37 | { | ||
| 38 | if (!valid_) | ||
| 39 | { | ||
| 40 | throw std::domain_error("Bad access to uninitialized form"); | ||
| 41 | } | ||
| 42 | |||
| 43 | return id_; | ||
| 44 | } | ||
| 45 | |||
| 46 | std::string getText() const | ||
| 47 | { | ||
| 48 | if (!valid_) | ||
| 49 | { | ||
| 50 | throw std::domain_error("Bad access to uninitialized form"); | ||
| 51 | } | ||
| 52 | |||
| 53 | return text_; | ||
| 54 | } | ||
| 55 | |||
| 56 | int getComplexity() const | ||
| 57 | { | ||
| 58 | if (!valid_) | ||
| 59 | { | ||
| 60 | throw std::domain_error("Bad access to uninitialized form"); | ||
| 61 | } | ||
| 62 | |||
| 63 | return complexity_; | ||
| 64 | } | ||
| 65 | |||
| 66 | bool isProper() const | ||
| 67 | { | ||
| 68 | if (!valid_) | ||
| 69 | { | ||
| 70 | throw std::domain_error("Bad access to uninitialized form"); | ||
| 71 | } | ||
| 72 | |||
| 73 | return proper_; | ||
| 74 | } | ||
| 75 | |||
| 76 | const std::vector<pronunciation>& getPronunciations() const; | ||
| 77 | |||
| 78 | // Type info | ||
| 79 | |||
| 80 | static const object objectType; | ||
| 81 | |||
| 82 | static const std::list<std::string> select; | ||
| 83 | |||
| 84 | // Query fields | ||
| 85 | |||
| 86 | static const field id; | ||
| 87 | static const field text; | ||
| 88 | static const field complexity; | ||
| 89 | static const field proper; | ||
| 90 | |||
| 91 | operator filter() const | ||
| 92 | { | ||
| 93 | if (!valid_) | ||
| 94 | { | ||
| 95 | throw std::domain_error("Bad access to uninitialized form"); | ||
| 96 | } | ||
| 97 | |||
| 98 | return (id == id_); | ||
| 99 | } | ||
| 100 | |||
| 101 | // Relationships to other objects | ||
| 102 | |||
| 103 | static const field pronunciation; | ||
| 104 | |||
| 105 | class inflection_field { | ||
| 106 | public: | ||
| 107 | |||
| 108 | inflection_field(inflection category) : category_(category) | ||
| 109 | { | ||
| 110 | } | ||
| 111 | |||
| 112 | const inflection getCategory() const | ||
| 113 | { | ||
| 114 | return category_; | ||
| 115 | } | ||
| 116 | |||
| 117 | private: | ||
| 118 | |||
| 119 | const inflection category_; | ||
| 120 | }; | ||
| 121 | |||
| 122 | static const inflection_field lemma(inflection category) | ||
| 123 | { | ||
| 124 | return inflection_field(category); | ||
| 125 | } | ||
| 126 | |||
| 127 | friend filter operator%=(form::inflection_field check, filter joinCondition); | ||
| 128 | |||
| 129 | private: | ||
| 130 | bool valid_ = false; | ||
| 131 | |||
| 132 | int id_; | ||
| 133 | std::string text_; | ||
| 134 | int complexity_ ; | ||
| 135 | bool proper_; | ||
| 136 | |||
| 137 | const database* db_; | ||
| 138 | |||
| 139 | mutable bool initializedPronunciations_ = false; | ||
| 140 | mutable std::vector<class pronunciation> pronunciations_; | ||
| 141 | |||
| 142 | static const field lemmaJoin; | ||
| 143 | static const field inflectionCategory; | ||
| 144 | |||
| 145 | }; | ||
| 146 | |||
| 147 | }; | ||
| 148 | |||
| 149 | #endif /* end of include guard: FORM_H_3A6C962C */ | ||
