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.h91
1 files changed, 53 insertions, 38 deletions
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 @@
10struct sqlite3_stmt; 10struct sqlite3_stmt;
11 11
12namespace verbly { 12namespace verbly {
13 13
14 class form; 14 class form;
15 class word; 15 class word;
16 class database; 16 class database;
17 17
18 class pronunciation { 18 class pronunciation {
19 public: 19 public:
20 20
21 // Default constructor 21 // Default constructor
22 22
23 pronunciation() = default; 23 pronunciation() = default;
24 24
25 // Construct from database 25 // Construct from database
26 26
27 pronunciation(const database& db, sqlite3_stmt* row); 27 pronunciation(const database& db, sqlite3_stmt* row);
28 28
29 // Accessors 29 // Accessors
30 30
31 bool isValid() const 31 bool isValid() const
32 { 32 {
33 return valid_; 33 return valid_;
34 } 34 }
35 35
36 int getId() const 36 int getId() const
37 { 37 {
38 if (!valid_) 38 if (!valid_)
39 { 39 {
40 throw std::domain_error("Bad access to uninitialized pronunciation"); 40 throw std::domain_error("Bad access to uninitialized pronunciation");
41 } 41 }
42 42
43 return id_; 43 return id_;
44 } 44 }
45 45
46 const std::vector<std::string>& getPhonemes() const 46 const std::vector<std::string>& getPhonemes() const
47 { 47 {
48 if (!valid_) 48 if (!valid_)
49 { 49 {
50 throw std::domain_error("Bad access to uninitialized pronunciation"); 50 throw std::domain_error("Bad access to uninitialized pronunciation");
51 } 51 }
52 52
53 return phonemes_; 53 return phonemes_;
54 } 54 }
55 55
56 int getSyllables() const 56 int getSyllables() const
57 { 57 {
58 if (!valid_) 58 if (!valid_)
59 { 59 {
60 throw std::domain_error("Bad access to uninitialized pronunciation"); 60 throw std::domain_error("Bad access to uninitialized pronunciation");
61 } 61 }
62 62
63 return syllables_; 63 return syllables_;
64 } 64 }
65 65
66 std::string getStress() const 66 std::string getStress() const
67 { 67 {
68 if (!valid_) 68 if (!valid_)
69 { 69 {
70 throw std::domain_error("Bad access to uninitialized pronunciation"); 70 throw std::domain_error("Bad access to uninitialized pronunciation");
71 } 71 }
72 72
73 return stress_; 73 return stress_;
74 } 74 }
75 75
76 bool hasRhyme() const 76 bool hasRhyme() const
77 { 77 {
78 if (!valid_) 78 if (!valid_)
79 { 79 {
80 throw std::domain_error("Bad access to uninitialized pronunciation"); 80 throw std::domain_error("Bad access to uninitialized pronunciation");
81 } 81 }
82 82
83 return hasRhyme_; 83 return hasRhyme_;
84 } 84 }
85 85
86 std::string getPrerhyme() const 86 std::string getPrerhyme() const
87 { 87 {
88 if (!valid_) 88 if (!valid_)
89 { 89 {
90 throw std::domain_error("Bad access to uninitialized pronunciation"); 90 throw std::domain_error("Bad access to uninitialized pronunciation");
91 } 91 }
92 92
93 if (!hasRhyme_) 93 if (!hasRhyme_)
94 { 94 {
95 throw std::domain_error("This pronunciation has no rhyme"); 95 throw std::domain_error("This pronunciation has no rhyme");
96 } 96 }
97 97
98 return prerhyme_; 98 return prerhyme_;
99 } 99 }
100 100
101 std::string getRhyme() const 101 std::string getRhyme() const
102 { 102 {
103 if (!valid_) 103 if (!valid_)
104 { 104 {
105 throw std::domain_error("Bad access to uninitialized pronunciation"); 105 throw std::domain_error("Bad access to uninitialized pronunciation");
106 } 106 }
107 107
108 if (!hasRhyme_) 108 if (!hasRhyme_)
109 { 109 {
110 throw std::domain_error("This pronunciation has no rhyme"); 110 throw std::domain_error("This pronunciation has no rhyme");
111 } 111 }
112 112
113 return rhyme_; 113 return rhyme_;
114 } 114 }
115 115
116 // Type info 116 // Type info
117 117
118 static const object objectType; 118 static const object objectType;
119 119
120 static const std::list<std::string> select; 120 static const std::list<std::string> select;
121 121
122 // Query fields 122 // Query fields
123 123
124 static const field id; 124 static const field id;
125 static const field numOfSyllables; 125 static const field numOfSyllables;
126 static const field stress; 126 static const field stress;
127 127
128 operator filter() const 128 operator filter() const
129 { 129 {
130 if (!valid_)
131 {
132 throw std::domain_error("Bad access to uninitialized pronunciation");
133 }
134
130 return (id == id_); 135 return (id == id_);
131 } 136 }
132 137
138 filter operator!() const
139 {
140 if (!valid_)
141 {
142 throw std::domain_error("Bad access to uninitialized pronunciation");
143 }
144
145 return (id != id_);
146 }
147
133 // Relationships to other objects 148 // Relationships to other objects
134 149
135 static const field forms; 150 static const field forms;
136 151
137 // Rhyming relationship 152 // Rhyming relationship
@@ -150,10 +165,10 @@ namespace verbly {
150 }; 165 };
151 166
152 static const rhymes_field rhymes; 167 static const rhymes_field rhymes;
153 168
154 private: 169 private:
155 bool valid_ = false; 170 bool valid_ = false;
156 171
157 int id_; 172 int id_;
158 std::vector<std::string> phonemes_; 173 std::vector<std::string> phonemes_;
159 int syllables_; 174 int syllables_;
@@ -161,14 +176,14 @@ namespace verbly {
161 bool hasRhyme_ = false; 176 bool hasRhyme_ = false;
162 std::string prerhyme_; 177 std::string prerhyme_;
163 std::string rhyme_; 178 std::string rhyme_;
164 179
165 const database* db_; 180 const database* db_;
166 181
167 static const field prerhyme; 182 static const field prerhyme;
168 static const field rhyme; 183 static const field rhyme;
169 184
170 }; 185 };
171 186
172}; 187};
173 188
174#endif /* end of include guard: PRONUNCIATION_H_C68F86B0 */ 189#endif /* end of include guard: PRONUNCIATION_H_C68F86B0 */