diff options
-rw-r--r-- | adjective.h | 2 | ||||
-rw-r--r-- | adverb.h | 21 | ||||
-rw-r--r-- | data.h | 79 | ||||
-rw-r--r-- | token.h | 21 | ||||
-rw-r--r-- | verbly.h | 1 |
5 files changed, 106 insertions, 18 deletions
diff --git a/adjective.h b/adjective.h index 58c490e..9d7883f 100644 --- a/adjective.h +++ b/adjective.h | |||
@@ -8,7 +8,7 @@ namespace verbly { | |||
8 | int id; | 8 | int id; |
9 | 9 | ||
10 | public: | 10 | public: |
11 | std::string value; | 11 | std::string form; |
12 | 12 | ||
13 | adjective(int id) : id(id) | 13 | adjective(int id) : id(id) |
14 | { | 14 | { |
diff --git a/adverb.h b/adverb.h new file mode 100644 index 0000000..6d2466e --- /dev/null +++ b/adverb.h | |||
@@ -0,0 +1,21 @@ | |||
1 | #ifndef ADVERB_H_86F8302F | ||
2 | #define ADVERB_H_86F8302F | ||
3 | |||
4 | namespace verbly { | ||
5 | |||
6 | class adverb { | ||
7 | private: | ||
8 | int id; | ||
9 | |||
10 | public: | ||
11 | std::string form; | ||
12 | |||
13 | adverb(int id) : id(id) | ||
14 | { | ||
15 | |||
16 | } | ||
17 | }; | ||
18 | |||
19 | }; | ||
20 | |||
21 | #endif /* end of include guard: ADVERB_H_86F8302F */ | ||
diff --git a/data.h b/data.h index 2c23c15..e901cba 100644 --- a/data.h +++ b/data.h | |||
@@ -121,7 +121,7 @@ namespace verbly { | |||
121 | std::list<adjective> run() const | 121 | std::list<adjective> run() const |
122 | { | 122 | { |
123 | std::stringstream construct; | 123 | std::stringstream construct; |
124 | construct << "SELECT adjective_id, adjective FROM adjectives"; | 124 | construct << "SELECT adjective_id, form FROM adjectives"; |
125 | 125 | ||
126 | if (m_random) | 126 | if (m_random) |
127 | { | 127 | { |
@@ -144,7 +144,77 @@ namespace verbly { | |||
144 | while (sqlite3_step(ppstmt) == SQLITE_ROW) | 144 | while (sqlite3_step(ppstmt) == SQLITE_ROW) |
145 | { | 145 | { |
146 | adjective tnc {sqlite3_column_int(ppstmt, 0)}; | 146 | adjective tnc {sqlite3_column_int(ppstmt, 0)}; |
147 | tnc.value = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); | 147 | tnc.form = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); |
148 | |||
149 | output.push_back(tnc); | ||
150 | } | ||
151 | |||
152 | sqlite3_finalize(ppstmt); | ||
153 | |||
154 | return output; | ||
155 | } | ||
156 | |||
157 | }; | ||
158 | |||
159 | class adverb_query { | ||
160 | public: | ||
161 | const static int unlimited = -1; | ||
162 | |||
163 | private: | ||
164 | const data& database; | ||
165 | int m_limit = unlimited; | ||
166 | bool m_random = false; | ||
167 | |||
168 | public: | ||
169 | adverb_query(const data& database) : database(database) | ||
170 | { | ||
171 | |||
172 | } | ||
173 | |||
174 | adverb_query& limit(int m_limit) | ||
175 | { | ||
176 | if ((m_limit > 0) || (m_limit == unlimited)) | ||
177 | { | ||
178 | this->m_limit = m_limit; | ||
179 | } | ||
180 | |||
181 | return *this; | ||
182 | } | ||
183 | |||
184 | adverb_query& random(bool m_random) | ||
185 | { | ||
186 | this->m_random = m_random; | ||
187 | |||
188 | return *this; | ||
189 | } | ||
190 | |||
191 | std::list<adverb> run() const | ||
192 | { | ||
193 | std::stringstream construct; | ||
194 | construct << "SELECT adverb_id, form FROM adverbs"; | ||
195 | |||
196 | if (m_random) | ||
197 | { | ||
198 | construct << " ORDER BY RANDOM()"; | ||
199 | } | ||
200 | |||
201 | if (m_limit != unlimited) | ||
202 | { | ||
203 | construct << " LIMIT " << m_limit; | ||
204 | } | ||
205 | |||
206 | sqlite3_stmt* ppstmt; | ||
207 | std::string query = construct.str(); | ||
208 | if (sqlite3_prepare_v2(database.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) | ||
209 | { | ||
210 | throw std::runtime_error(sqlite3_errmsg(database.ppdb)); | ||
211 | } | ||
212 | |||
213 | std::list<adverb> output; | ||
214 | while (sqlite3_step(ppstmt) == SQLITE_ROW) | ||
215 | { | ||
216 | adverb tnc {sqlite3_column_int(ppstmt, 0)}; | ||
217 | tnc.form = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); | ||
148 | 218 | ||
149 | output.push_back(tnc); | 219 | output.push_back(tnc); |
150 | } | 220 | } |
@@ -194,6 +264,11 @@ namespace verbly { | |||
194 | return adjective_query(*this); | 264 | return adjective_query(*this); |
195 | } | 265 | } |
196 | 266 | ||
267 | adverb_query adverbs() const | ||
268 | { | ||
269 | return adverb_query(*this); | ||
270 | } | ||
271 | |||
197 | }; | 272 | }; |
198 | 273 | ||
199 | }; | 274 | }; |
diff --git a/token.h b/token.h index bbe7c2d..2848fd0 100644 --- a/token.h +++ b/token.h | |||
@@ -24,7 +24,8 @@ namespace verbly { | |||
24 | enum class fillin_type { | 24 | enum class fillin_type { |
25 | noun_phrase, | 25 | noun_phrase, |
26 | participle_phrase, | 26 | participle_phrase, |
27 | adjective | 27 | adjective, |
28 | adverb | ||
28 | }; | 29 | }; |
29 | 30 | ||
30 | class token { | 31 | class token { |
@@ -128,14 +129,14 @@ namespace verbly { | |||
128 | return it != other.it; | 129 | return it != other.it; |
129 | } | 130 | } |
130 | 131 | ||
131 | token* operator*() | 132 | token& operator*() |
132 | { | 133 | { |
133 | return *it->get(); | 134 | return **it; |
134 | } | 135 | } |
135 | 136 | ||
136 | token* operator->() | 137 | token& operator->() |
137 | { | 138 | { |
138 | return *it->get(); | 139 | return **it; |
139 | } | 140 | } |
140 | };*/ | 141 | };*/ |
141 | 142 | ||
@@ -189,16 +190,6 @@ namespace verbly { | |||
189 | return std::end(utterance); | 190 | return std::end(utterance); |
190 | } | 191 | } |
191 | 192 | ||
192 | const iterator begin() const | ||
193 | { | ||
194 | return std::begin(utterance); | ||
195 | } | ||
196 | |||
197 | const iterator end() const | ||
198 | { | ||
199 | return std::end(utterance); | ||
200 | } | ||
201 | |||
202 | void erase(iterator it) | 193 | void erase(iterator it) |
203 | { | 194 | { |
204 | utterance.erase(it); | 195 | utterance.erase(it); |
diff --git a/verbly.h b/verbly.h index 139d8f8..44fd3a8 100644 --- a/verbly.h +++ b/verbly.h | |||
@@ -5,6 +5,7 @@ | |||
5 | #include "token.h" | 5 | #include "token.h" |
6 | #include "verb.h" | 6 | #include "verb.h" |
7 | #include "adjective.h" | 7 | #include "adjective.h" |
8 | #include "adverb.h" | ||
8 | #include "data.h" | 9 | #include "data.h" |
9 | 10 | ||
10 | #endif /* end of include guard: VERBLY_H_5B39CE50 */ | 11 | #endif /* end of include guard: VERBLY_H_5B39CE50 */ |