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