diff options
Diffstat (limited to 'lib/part.h')
-rw-r--r-- | lib/part.h | 97 |
1 files changed, 40 insertions, 57 deletions
diff --git a/lib/part.h b/lib/part.h index 456bad0..7783a61 100644 --- a/lib/part.h +++ b/lib/part.h | |||
@@ -5,12 +5,12 @@ | |||
5 | #include <vector> | 5 | #include <vector> |
6 | #include <set> | 6 | #include <set> |
7 | #include <list> | 7 | #include <list> |
8 | #include <hkutil/database.h> | ||
9 | #include <variant.hpp> | ||
8 | #include "field.h" | 10 | #include "field.h" |
9 | #include "filter.h" | 11 | #include "filter.h" |
10 | #include "enums.h" | 12 | #include "enums.h" |
11 | 13 | ||
12 | struct sqlite3_stmt; | ||
13 | |||
14 | namespace verbly { | 14 | namespace verbly { |
15 | 15 | ||
16 | class database; | 16 | class database; |
@@ -20,11 +20,16 @@ namespace verbly { | |||
20 | 20 | ||
21 | // Static factories | 21 | // Static factories |
22 | 22 | ||
23 | static part createNounPhrase(std::string role, std::set<std::string> selrestrs, std::set<std::string> synrestrs); | 23 | static part createNounPhrase( |
24 | std::string role, | ||
25 | std::set<std::string> selrestrs, | ||
26 | std::set<std::string> synrestrs); | ||
24 | 27 | ||
25 | static part createVerb(); | 28 | static part createVerb(); |
26 | 29 | ||
27 | static part createPreposition(std::vector<std::string> choices, bool literal); | 30 | static part createPreposition( |
31 | std::vector<std::string> choices, | ||
32 | bool literal); | ||
28 | 33 | ||
29 | static part createAdjective(); | 34 | static part createAdjective(); |
30 | 35 | ||
@@ -32,41 +37,12 @@ namespace verbly { | |||
32 | 37 | ||
33 | static part createLiteral(std::string value); | 38 | static part createLiteral(std::string value); |
34 | 39 | ||
35 | // Default constructor | ||
36 | |||
37 | part() | ||
38 | { | ||
39 | } | ||
40 | |||
41 | // Construct from database | 40 | // Construct from database |
42 | 41 | ||
43 | part(const database& db, sqlite3_stmt* row); | 42 | part(const database& db, hatkirby::row row); |
44 | |||
45 | // Copy and move constructors | ||
46 | |||
47 | part(const part& other); | ||
48 | |||
49 | part(part&& other); | ||
50 | |||
51 | // Assignment | ||
52 | |||
53 | part& operator=(part other); | ||
54 | |||
55 | // Swap | ||
56 | |||
57 | friend void swap(part& first, part& second); | ||
58 | |||
59 | // Destructor | ||
60 | |||
61 | ~part(); | ||
62 | 43 | ||
63 | // General accessors | 44 | // General accessors |
64 | 45 | ||
65 | bool isValid() const | ||
66 | { | ||
67 | return (type_ != part_type::invalid); | ||
68 | } | ||
69 | |||
70 | part_type getType() const | 46 | part_type getType() const |
71 | { | 47 | { |
72 | return type_; | 48 | return type_; |
@@ -74,23 +50,23 @@ namespace verbly { | |||
74 | 50 | ||
75 | // Noun phrase accessors | 51 | // Noun phrase accessors |
76 | 52 | ||
77 | std::string getNounRole() const; | 53 | const std::string& getNounRole() const; |
78 | 54 | ||
79 | std::set<std::string> getNounSelrestrs() const; | 55 | const std::set<std::string>& getNounSelrestrs() const; |
80 | 56 | ||
81 | std::set<std::string> getNounSynrestrs() const; | 57 | const std::set<std::string>& getNounSynrestrs() const; |
82 | 58 | ||
83 | bool nounHasSynrestr(std::string synrestr) const; | 59 | bool nounHasSynrestr(std::string synrestr) const; |
84 | 60 | ||
85 | // Preposition accessors | 61 | // Preposition accessors |
86 | 62 | ||
87 | std::vector<std::string> getPrepositionChoices() const; | 63 | const std::vector<std::string>& getPrepositionChoices() const; |
88 | 64 | ||
89 | bool isPrepositionLiteral() const; | 65 | bool isPrepositionLiteral() const; |
90 | 66 | ||
91 | // Literal accessors | 67 | // Literal accessors |
92 | 68 | ||
93 | std::string getLiteralValue() const; | 69 | const std::string& getLiteralValue() const; |
94 | 70 | ||
95 | // Type info | 71 | // Type info |
96 | 72 | ||
@@ -123,7 +99,7 @@ namespace verbly { | |||
123 | }; | 99 | }; |
124 | 100 | ||
125 | static const selrestr_field selrestrs; | 101 | static const selrestr_field selrestrs; |
126 | 102 | ||
127 | class synrestr_field { | 103 | class synrestr_field { |
128 | public: | 104 | public: |
129 | 105 | ||
@@ -139,29 +115,36 @@ namespace verbly { | |||
139 | 115 | ||
140 | private: | 116 | private: |
141 | 117 | ||
142 | // Private constructors | ||
143 | |||
144 | part(part_type t) : type_(t) | ||
145 | { | ||
146 | } | ||
147 | |||
148 | // Data | 118 | // Data |
149 | 119 | ||
150 | union { | 120 | struct np_type { |
151 | struct { | 121 | std::string role; |
152 | std::string role; | 122 | std::set<std::string> selrestrs; |
153 | std::set<std::string> selrestrs; | 123 | std::set<std::string> synrestrs; |
154 | std::set<std::string> synrestrs; | 124 | }; |
155 | } noun_phrase_; | 125 | |
156 | struct { | 126 | struct prep_type { |
157 | std::vector<std::string> choices; | 127 | std::vector<std::string> choices; |
158 | bool literal; | 128 | bool literal; |
159 | } preposition_; | ||
160 | std::string literal_; | ||
161 | }; | 129 | }; |
162 | 130 | ||
131 | using variant_type = | ||
132 | mpark::variant< | ||
133 | mpark::monostate, | ||
134 | np_type, | ||
135 | prep_type, | ||
136 | std::string>; | ||
137 | |||
138 | variant_type variant_; | ||
139 | |||
163 | part_type type_ = part_type::invalid; | 140 | part_type type_ = part_type::invalid; |
164 | 141 | ||
142 | // Private constructors | ||
143 | |||
144 | part(part_type t, variant_type v = {}) : type_(t), variant_(v) | ||
145 | { | ||
146 | } | ||
147 | |||
165 | }; | 148 | }; |
166 | 149 | ||
167 | }; | 150 | }; |