Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Multiplexer.cpp
Go to the documentation of this file.
1#include "joedb/Multiplexer.h"
2
3namespace joedb
4{
5 ////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////
8 (
9 std::initializer_list<std::reference_wrapper<Writable>> initializer_list
10 ):
11 writables(initializer_list),
12 start_index(0)
13 {
14 }
15
16 #define MULTIPLEX(x) do {for (size_t i = start_index; i < writables.size(); i++) writables[i].get().x;} while(0)
17
18 ////////////////////////////////////////////////////////////////////////////
19 void Multiplexer::create_table(const std::string &name)
20 ////////////////////////////////////////////////////////////////////////////
21 {
23 }
24
25 ////////////////////////////////////////////////////////////////////////////
27 ////////////////////////////////////////////////////////////////////////////
28 {
29 MULTIPLEX(drop_table(table_id));
30 }
31
32 ////////////////////////////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////////////////////////////
35 (
36 Table_Id table_id,
37 const std::string &name
38 )
39 {
40 MULTIPLEX(rename_table(table_id, name));
41 }
42
43 ////////////////////////////////////////////////////////////////////////////
45 ////////////////////////////////////////////////////////////////////////////
46 (
47 Table_Id table_id,
48 const std::string &name,
49 Type type
50 )
51 {
52 MULTIPLEX(add_field(table_id, name, type));
53 }
54
55 ////////////////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////////////////
58 (
59 Table_Id table_id,
60 Field_Id field_id
61 )
62 {
63 MULTIPLEX(drop_field(table_id, field_id));
64 }
65
66 ////////////////////////////////////////////////////////////////////////////
68 ////////////////////////////////////////////////////////////////////////////
69 (
70 Table_Id table_id,
71 Field_Id field_id,
72 const std::string &name
73 )
74 {
75 MULTIPLEX(rename_field(table_id, field_id, name));
76 }
77
78 ////////////////////////////////////////////////////////////////////////////
79 void Multiplexer::custom(const std::string &name)
80 ////////////////////////////////////////////////////////////////////////////
81 {
82 MULTIPLEX(custom(name));
83 }
84
85 ////////////////////////////////////////////////////////////////////////////
86 void Multiplexer::comment(const std::string &comment)
87 ////////////////////////////////////////////////////////////////////////////
88 {
90 }
91
92 ////////////////////////////////////////////////////////////////////////////
93 void Multiplexer::timestamp(int64_t timestamp)
94 ////////////////////////////////////////////////////////////////////////////
95 {
97 }
98
99 ////////////////////////////////////////////////////////////////////////////
101 ////////////////////////////////////////////////////////////////////////////
102 {
104 }
105
106 ////////////////////////////////////////////////////////////////////////////
108 ////////////////////////////////////////////////////////////////////////////
109 {
110 MULTIPLEX(flush());
111 }
112
113 ////////////////////////////////////////////////////////////////////////////
115 ////////////////////////////////////////////////////////////////////////////
116 {
117 int64_t result = 0;
118
119 for (auto w: writables)
120 {
121 result = w.get().get_position();
122 if (result > 0)
123 break;
124 }
125
126 return result;
127 }
128
129 ////////////////////////////////////////////////////////////////////////////
130 void Multiplexer::start_writing(int64_t position)
131 ////////////////////////////////////////////////////////////////////////////
132 {
133 MULTIPLEX(start_writing(position));
134 }
135
136 ////////////////////////////////////////////////////////////////////////////
137 void Multiplexer::end_writing(int64_t position)
138 ////////////////////////////////////////////////////////////////////////////
139 {
140 MULTIPLEX(end_writing(position));
141 }
142
143 ////////////////////////////////////////////////////////////////////////////
145 ////////////////////////////////////////////////////////////////////////////
146 {
148 }
149
150 ////////////////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////////
153 {
155 }
156
157 ////////////////////////////////////////////////////////////////////////////
159 ////////////////////////////////////////////////////////////////////////////
160 (
161 Table_Id table_id,
162 Record_Id record_id
163 )
164 {
165 MULTIPLEX(insert_into(table_id, record_id));
166 }
167
168 ////////////////////////////////////////////////////////////////////////////
170 ////////////////////////////////////////////////////////////////////////////
171 (
172 Table_Id table_id,
173 Record_Id record_id
174 )
175 {
176 MULTIPLEX(delete_from(table_id, record_id));
177 }
178
179 ////////////////////////////////////////////////////////////////////////////
181 ////////////////////////////////////////////////////////////////////////////
182 (
183 Table_Id table_id,
184 Record_Id record_id,
185 size_t size
186 )
187 {
188 MULTIPLEX(insert_vector(table_id, record_id, size));
189 }
190
191 ////////////////////////////////////////////////////////////////////////////
193 ////////////////////////////////////////////////////////////////////////////
194 (
195 Table_Id table_id,
196 Record_Id record_id,
197 size_t size
198 )
199 {
200 MULTIPLEX(delete_vector(table_id, record_id, size));
201 }
202
203 #define TYPE_MACRO(type, return_type, type_id, R, W)\
204 void Multiplexer::update_##type_id\
205 (\
206 Table_Id table_id,\
207 Record_Id record_id,\
208 Field_Id field_id,\
209 return_type value\
210 )\
211 {\
212 MULTIPLEX(update_##type_id(table_id, record_id, field_id, value));\
213 }\
214 void Multiplexer::update_vector_##type_id\
215 (\
216 Table_Id table_id,\
217 Record_Id record_id,\
218 Field_Id field_id,\
219 size_t size,\
220 const type *value\
221 )\
222 {\
223 MULTIPLEX\
224 (\
225 update_vector_##type_id(table_id, record_id, field_id, size, value)\
226 );\
227 }\
228 type *Multiplexer::get_own_##type_id##_storage\
229 (\
230 Table_Id table_id,\
231 Record_Id record_id,\
232 Field_Id field_id,\
233 size_t &capacity\
234 )\
235 {\
236 capacity = 0;\
237 type *result = nullptr;\
238 for (auto w: writables)\
239 {\
240 result = w.get().get_own_##type_id##_storage(table_id, record_id, field_id, capacity);\
241 if (result)\
242 break;\
243 }\
244 return result;\
245 }
246 #include "joedb/TYPE_MACRO.h"
247
248 ////////////////////////////////////////////////////////////////////////////
250 ////////////////////////////////////////////////////////////////////////////
251 {
252 MULTIPLEX(on_blob(blob));
253 }
254
255 #undef MULTIPLEX
256
257 ////////////////////////////////////////////////////////////////////////////
259 ////////////////////////////////////////////////////////////////////////////
260 {
261 for (auto w: writables)
262 {
263 if (w.get().wants_blob_data())
264 return true;
265 }
266
267 return false;
268 }
269
270 ////////////////////////////////////////////////////////////////////////////
271 Blob Multiplexer::write_blob(const std::string &data)
272 ////////////////////////////////////////////////////////////////////////////
273 {
274 Blob result;
275
276 for (auto w: writables)
277 {
278 if (w.get().wants_blob_data())
279 result = w.get().write_blob(data);
280 }
281
282 return result;
283 }
284
285 ////////////////////////////////////////////////////////////////////////////
286 Multiplexer::~Multiplexer() = default;
287 ////////////////////////////////////////////////////////////////////////////
288}
#define MULTIPLEX(x)
void soft_checkpoint() override
void insert_into(Table_Id table_id, Record_Id record_id) override
void comment(const std::string &comment) override
bool wants_blob_data() const override
~Multiplexer() override
Blob write_blob(const std::string &data) override
void custom(const std::string &name) override
void create_table(const std::string &name) override
int64_t get_position() const override
void rename_field(Table_Id table_id, Field_Id field_id, const std::string &name) override
void drop_field(Table_Id table_id, Field_Id field_id) override
void valid_data() override
void timestamp(int64_t timestamp) override
void end_writing(int64_t position) override
void add_field(Table_Id table_id, const std::string &name, Type type) override
void delete_from(Table_Id table_id, Record_Id record_id) override
void on_blob(Blob blob) override
void rename_table(Table_Id table_id, const std::string &name) override
void flush() override
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void hard_checkpoint() override
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) override
void start_writing(int64_t position) override
void drop_table(Table_Id table_id) override
Multiplexer(std::initializer_list< std::reference_wrapper< Writable > > initializer_list)
Definition Blob.h:7