summary refs log tree commit diff stats
path: root/lib/binding.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/binding.cpp')
-rw-r--r--lib/binding.cpp249
1 files changed, 0 insertions, 249 deletions
diff --git a/lib/binding.cpp b/lib/binding.cpp deleted file mode 100644 index 0b58785..0000000 --- a/lib/binding.cpp +++ /dev/null
@@ -1,249 +0,0 @@
1#include "binding.h"
2#include <stdexcept>
3#include <utility>
4
5namespace verbly {
6
7 binding::binding(const binding& other)
8 {
9 type_ = other.type_;
10
11 switch (type_)
12 {
13 case type::integer:
14 {
15 integer_ = other.integer_;
16
17 break;
18 }
19
20 case type::string:
21 {
22 new(&string_) std::string(other.string_);
23
24 break;
25 }
26
27 case type::field:
28 {
29 new(&field_.table_) std::string(other.field_.table_);
30 new(&field_.column_) std::string(other.field_.column_);
31
32 break;
33 }
34
35 case type::invalid:
36 {
37 break;
38 }
39 }
40 }
41
42 binding::binding(binding&& other) : binding()
43 {
44 swap(*this, other);
45 }
46
47 binding& binding::operator=(binding other)
48 {
49 swap(*this, other);
50
51 return *this;
52 }
53
54 void swap(binding& first, binding& second)
55 {
56 using type = binding::type;
57
58 type tempType = first.type_;
59 int tempInteger;
60 std::string tempString;
61 std::string tempTable;
62 std::string tempColumn;
63
64 switch (first.type_)
65 {
66 case type::integer:
67 {
68 tempInteger = first.integer_;
69
70 break;
71 }
72
73 case type::string:
74 {
75 tempString = std::move(tempString);
76
77 break;
78 }
79
80 case type::field:
81 {
82 tempTable = std::move(first.field_.table_);
83 tempColumn = std::move(first.field_.column_);
84
85 break;
86 }
87
88 case type::invalid:
89 {
90 break;
91 }
92 }
93
94 first.~binding();
95
96 first.type_ = second.type_;
97
98 switch (second.type_)
99 {
100 case type::integer:
101 {
102 first.integer_ = second.integer_;
103
104 break;
105 }
106
107 case type::string:
108 {
109 new(&first.string_) std::string(std::move(second.string_));
110
111 break;
112 }
113
114 case type::field:
115 {
116 new(&first.field_.table_) std::string(std::move(second.field_.table_));
117 new(&first.field_.column_) std::string(std::move(second.field_.column_));
118
119 break;
120 }
121
122 case type::invalid:
123 {
124 break;
125 }
126 }
127
128 second.~binding();
129
130 second.type_ = tempType;
131
132 switch (tempType)
133 {
134 case type::integer:
135 {
136 second.integer_ = tempInteger;
137
138 break;
139 }
140
141 case type::string:
142 {
143 new(&second.string_) std::string(std::move(tempString));
144
145 break;
146 }
147
148 case type::field:
149 {
150 new(&first.field_.table_) std::string(std::move(tempTable));
151 new(&first.field_.column_) std::string(std::move(tempColumn));
152
153 break;
154 }
155
156 case type::invalid:
157 {
158 break;
159 }
160 }
161 }
162
163 binding::~binding()
164 {
165 switch (type_)
166 {
167 case type::string:
168 {
169 using string_type = std::string;
170 string_.~string_type();
171
172 break;
173 }
174
175 case type::field:
176 {
177 using string_type = std::string;
178 field_.table_.~string_type();
179 field_.column_.~string_type();
180
181 break;
182 }
183
184 case type::integer:
185 case type::invalid:
186 {
187 break;
188 }
189 }
190 }
191
192 binding::binding(int arg) :
193 type_(type::integer),
194 integer_(arg)
195 {
196 }
197
198 int binding::getInteger() const
199 {
200 if (type_ != type::integer)
201 {
202 throw std::domain_error("binding::getInteger called on non-integer binding");
203 }
204
205 return integer_;
206 }
207
208 binding::binding(std::string arg) : type_(type::string)
209 {
210 new(&string_) std::string(std::move(arg));
211 }
212
213 std::string binding::getString() const
214 {
215 if (type_ != type::string)
216 {
217 throw std::domain_error("binding::getString called on non-string binding");
218 }
219
220 return string_;
221 }
222
223 binding::binding(std::string table, std::string column) : type_(type::field)
224 {
225 new(&field_.table_) std::string(std::move(table));
226 new(&field_.column_) std::string(std::move(column));
227 }
228
229 std::string binding::getTable() const
230 {
231 if (type_ != type::field)
232 {
233 throw std::domain_error("binding::getTable called on non-field binding");
234 }
235
236 return field_.table_;
237 }
238
239 std::string binding::getColumn() const
240 {
241 if (type_ != type::field)
242 {
243 throw std::domain_error("binding::getColumn called on non-field binding");
244 }
245
246 return field_.column_;
247 }
248
249};