summary refs log tree commit diff stats
path: root/lib/pronunciation.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pronunciation.h')
-rw-r--r--lib/pronunciation.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/lib/pronunciation.h b/lib/pronunciation.h new file mode 100644 index 0000000..c7a1d4d --- /dev/null +++ b/lib/pronunciation.h
@@ -0,0 +1,163 @@
1#ifndef PRONUNCIATION_H_C68F86B0
2#define PRONUNCIATION_H_C68F86B0
3
4#include <stdexcept>
5#include <vector>
6#include <string>
7#include "field.h"
8#include "filter.h"
9
10struct sqlite3_stmt;
11
12namespace verbly {
13
14 class form;
15 class lemma;
16 class word;
17 class database;
18
19 class pronunciation {
20 public:
21
22 // Default constructor
23
24 pronunciation() = default;
25
26 // Construct from database
27
28 pronunciation(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 pronunciation");
42 }
43
44 return id_;
45 }
46
47 const std::vector<std::string>& getPhonemes() const
48 {
49 if (!valid_)
50 {
51 throw std::domain_error("Bad access to uninitialized pronunciation");
52 }
53
54 return phonemes_;
55 }
56
57 int getSyllables() const
58 {
59 if (!valid_)
60 {
61 throw std::domain_error("Bad access to uninitialized pronunciation");
62 }
63
64 return syllables_;
65 }
66
67 std::string getStress() const
68 {
69 if (!valid_)
70 {
71 throw std::domain_error("Bad access to uninitialized pronunciation");
72 }
73
74 return stress_;
75 }
76
77 bool hasRhyme() const
78 {
79 if (!valid_)
80 {
81 throw std::domain_error("Bad access to uninitialized pronunciation");
82 }
83
84 return hasRhyme_;
85 }
86
87 std::string getPrerhyme() const
88 {
89 if (!valid_)
90 {
91 throw std::domain_error("Bad access to uninitialized pronunciation");
92 }
93
94 if (!hasRhyme_)
95 {
96 throw std::domain_error("This pronunciation has no rhyme");
97 }
98
99 return prerhyme_;
100 }
101
102 std::string getRhyme() const
103 {
104 if (!valid_)
105 {
106 throw std::domain_error("Bad access to uninitialized pronunciation");
107 }
108
109 if (!hasRhyme_)
110 {
111 throw std::domain_error("This pronunciation has no rhyme");
112 }
113
114 return rhyme_;
115 }
116
117 // Type info
118
119 static const object objectType;
120
121 static const std::list<std::string> select;
122
123 // Query fields
124
125 static const field id;
126 static const field numOfSyllables;
127 static const field stress;
128
129 operator filter() const
130 {
131 return (id == id_);
132 }
133
134 static filter rhymesWith(const pronunciation& arg);
135 static filter rhymesWith(const class form& arg);
136 static filter rhymesWith(const lemma& arg);
137 static filter rhymesWith(const word& arg);
138
139 // Relationships to other objects
140
141 static const field form;
142
143 private:
144 bool valid_ = false;
145
146 int id_;
147 std::vector<std::string> phonemes_;
148 int syllables_;
149 std::string stress_;
150 bool hasRhyme_ = false;
151 std::string prerhyme_;
152 std::string rhyme_;
153
154 const database* db_;
155
156 static const field prerhyme;
157 static const field rhyme;
158
159 };
160
161};
162
163#endif /* end of include guard: PRONUNCIATION_H_C68F86B0 */