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