Joedb 10.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Database.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//
3// This code was automatically generated by the joedb compiler
4// https://www.joedb.org/
5//
6// Path to compiler: /home/rcoulom/repos/joedb/compcmake/gcc_debug/joedbc
7// Version: 10.5.0
8// joedbc compilation time: Oct 25 2026 16:06:59
9// Generation of this file: 2026-10-25 19:48:05 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef tutorial_rpc_population_Database_declared
13#define tutorial_rpc_population_Database_declared
14
17#include "joedb/error/assert.h"
18#include "joedb/get_version.h"
19#include "joedb/hash_combine.h"
20#include "ids.h"
21
22#include <string>
23#include <cstring>
24#include <vector>
25#include <algorithm>
26#include <string_view>
27#include <utility>
28
29
30static_assert(std::string_view(joedb::get_version()) == "10.5.0");
31
33{
34 /// @namespace tutorial::rpc::population
35 ///
36 /// Automatically generated by joedbc
37
38 using joedb::Record_Id;
39 using joedb::Table_Id;
40 using joedb::Field_Id;
41
44
45
46 namespace detail
47 {
48 struct data_of_city
49 {
50
51 joedb::Freedom_Keeper freedom_keeper;
52
53 size_t size() const {return freedom_keeper.size();}
54
55 void resize(size_t new_size)
56 {
57 freedom_keeper.resize(new_size);
58 }
59 };
60
61 struct data_of_data
62 {
63 std::vector<std::string> field_value_of_city_name;
64 std::vector<id_of_city> field_value_of_city;
65 std::vector<int64_t> field_value_of_population;
66
67 joedb::Freedom_Keeper freedom_keeper;
68
69 size_t size() const {return freedom_keeper.size();}
70
71 void resize(size_t new_size)
72 {
73 field_value_of_city_name.resize(new_size);
74 field_value_of_city.resize(new_size);
75 field_value_of_population.resize(new_size);
76 freedom_keeper.resize(new_size);
77 }
78 };
79 }
80
81
82 /// Store all the tables of the database
84 {
85 friend class Readable;
86 friend class container_of_city;
87 friend class container_of_data;
88
89 public:
90 template<typename E = joedb::Exception>
91 static void throw_exception(std::string_view message)
92 {
93 std::string s("tutorial::rpc::population: ");
94 s += message;
95 throw E(s);
96 }
97
98 bool is_valid(id_of_city id) const {return is_valid_record_id_for_city(id.get_record_id());}
99 bool is_valid(id_of_data id) const {return is_valid_record_id_for_data(id.get_record_id());}
100
101 protected:
102 detail::data_of_city storage_of_city;
103 bool is_valid_record_id_for_city(Record_Id record_id) const {return storage_of_city.freedom_keeper.is_used(record_id);}
104 detail::data_of_data storage_of_data;
105 bool is_valid_record_id_for_data(Record_Id record_id) const {return storage_of_data.freedom_keeper.is_used(record_id);}
106
108 {
110 storage_of_city.freedom_keeper.free(record_id);
111 }
113 {
115 storage_of_data.field_value_of_city_name[to_underlying(record_id)].clear();
116 storage_of_data.field_value_of_city[to_underlying(record_id)] = id_of_city(joedb::Record_Id::null);
117 storage_of_data.field_value_of_population[to_underlying(record_id)] = 0;
118 storage_of_data.freedom_keeper.free(record_id);
119 }
120
122 {
123 storage_of_city.freedom_keeper.use(record_id);
124 }
125
126 void internal_vector_insert_city(Record_Id record_id, size_t size)
127 {
128 JOEDB_RELEASE_ASSERT(storage_of_city.freedom_keeper.is_free_vector(record_id, size));
129 storage_of_city.freedom_keeper.use_vector(record_id, size);
130 }
132 {
133 storage_of_data.freedom_keeper.use(record_id);
134 }
135
136 void internal_vector_insert_data(Record_Id record_id, size_t size)
137 {
138 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_free_vector(record_id, size));
139 storage_of_data.freedom_keeper.use_vector(record_id, size);
140 }
141
143 (
144 Record_Id record_id,
145 std::string field_value_of_city_name
146 )
147 {
149 storage_of_data.field_value_of_city_name[to_underlying(record_id)] = std::move(field_value_of_city_name);
150 }
151
153 (
154 Record_Id record_id,
155 size_t size,
156 const std::string *value
157 )
158 {
159 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
160 std::string *target = &storage_of_data.field_value_of_city_name.data()[to_underlying(record_id)];
161 if (target != value)
162 std::copy_n(value, size, target);
163 }
164
166 (
167 Record_Id record_id,
168 id_of_city field_value_of_city
169 )
170 {
172 storage_of_data.field_value_of_city[to_underlying(record_id)] = field_value_of_city;
173 }
174
176 (
177 Record_Id record_id,
178 size_t size,
179 const id_of_city *value
180 )
181 {
182 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
183 id_of_city *target = &storage_of_data.field_value_of_city.data()[to_underlying(record_id)];
184 if (target != value)
185 std::copy_n(value, size, target);
186 }
187
189 (
190 Record_Id record_id,
191 int64_t field_value_of_population
192 )
193 {
195 storage_of_data.field_value_of_population[to_underlying(record_id)] = field_value_of_population;
196 }
197
199 (
200 Record_Id record_id,
201 size_t size,
202 const int64_t *value
203 )
204 {
205 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
206 int64_t *target = &storage_of_data.field_value_of_population.data()[to_underlying(record_id)];
207 if (target != value)
208 std::copy_n(value, size, target);
209 }
210
211 public:
213
215 {
216 return id_of_city
217 (
218 Record_Id(storage_of_city.freedom_keeper.get_next(id.get_record_id()))
219 );
220 }
221
223 {
224 return id_of_city
225 (
226 Record_Id(storage_of_city.freedom_keeper.get_previous(id.get_record_id()))
227 );
228 }
229
230 template<class Comparator>
231 std::vector<id_of_city> sorted_city(Comparator comparator) const;
232
234 {
235 return id_of_city();
236 }
237
239
241 {
242 return id_of_data
243 (
244 Record_Id(storage_of_data.freedom_keeper.get_next(id.get_record_id()))
245 );
246 }
247
249 {
250 return id_of_data
251 (
252 Record_Id(storage_of_data.freedom_keeper.get_previous(id.get_record_id()))
253 );
254 }
255
256 template<class Comparator>
257 std::vector<id_of_data> sorted_data(Comparator comparator) const;
258
260 {
261 return id_of_data();
262 }
263
264 const std::string & get_city_name(id_of_data record) const
265 {
267 return (const std::string &)(storage_of_data.field_value_of_city_name[record.get_id()]);
268 }
269
271 {
273 return (id_of_city)(storage_of_data.field_value_of_city[record.get_id()]);
274 }
275
276 int64_t get_population(id_of_data record) const
277 {
279 return (int64_t)(storage_of_data.field_value_of_population[record.get_id()]);
280 }
281 };
282 /// returned by @ref Database::get_city_table
283 class container_of_city
284 {
285 friend class Database;
286
287 private:
288 const Database &db;
289 container_of_city(const Database &db): db(db) {}
290
291 public:
292 class iterator
293 {
294 friend class container_of_city;
295 private:
296 const joedb::Freedom_Keeper *fk;
297 Record_Id index;
298 iterator(const detail::data_of_city &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
299 public:
300 using iterator_category = std::forward_iterator_tag;
302 using difference_type = std::ptrdiff_t;
305
306 bool operator==(const iterator &i) const {return index == i.index;}
307 bool operator!=(const iterator &i) const {return index != i.index;}
308 iterator &operator++() {index = fk->get_next(index); return *this;}
309 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
310 iterator &operator--() {index = fk->get_previous(index); return *this;}
311 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
312 id_of_city operator*() const {return id_of_city(Record_Id(index));}
313 };
314
315 iterator begin() const {return ++iterator(db.storage_of_city);}
316 iterator end() const {return iterator(db.storage_of_city);}
317 bool is_empty() const {return db.storage_of_city.freedom_keeper.get_used_count() == Record_Id{0};}
318 joedb::index_t get_size() const {return to_underlying(db.storage_of_city.freedom_keeper.get_used_count());}
319 static id_of_city get_at(size_t i) {return id_of_city(Record_Id(i));}
320 bool is_valid_at(size_t i) {return db.storage_of_city.freedom_keeper.is_used(Record_Id(i));}
321 id_of_city first() const {return *begin();}
322 id_of_city last() const {return *--end();}
323 id_of_city get_end() const {return *end();}
324 };
325
327 {
328 return container_of_city(*this);
329 }
330
331 template<class Comparator>
332 std::vector<id_of_city> Database::sorted_city(Comparator comparator) const
333 {
334 std::vector<id_of_city> result;
335 for (auto x: get_city_table())
336 result.emplace_back(x);
337 std::sort(result.begin(), result.end(), comparator);
338 return result;
339 }
340 /// returned by @ref Database::get_data_table
341 class container_of_data
342 {
343 friend class Database;
344
345 private:
346 const Database &db;
347 container_of_data(const Database &db): db(db) {}
348
349 public:
350 class iterator
351 {
352 friend class container_of_data;
353 private:
354 const joedb::Freedom_Keeper *fk;
355 Record_Id index;
356 iterator(const detail::data_of_data &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
357 public:
358 using iterator_category = std::forward_iterator_tag;
360 using difference_type = std::ptrdiff_t;
363
364 bool operator==(const iterator &i) const {return index == i.index;}
365 bool operator!=(const iterator &i) const {return index != i.index;}
366 iterator &operator++() {index = fk->get_next(index); return *this;}
367 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
368 iterator &operator--() {index = fk->get_previous(index); return *this;}
369 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
370 id_of_data operator*() const {return id_of_data(Record_Id(index));}
371 };
372
373 iterator begin() const {return ++iterator(db.storage_of_data);}
374 iterator end() const {return iterator(db.storage_of_data);}
375 bool is_empty() const {return db.storage_of_data.freedom_keeper.get_used_count() == Record_Id{0};}
376 joedb::index_t get_size() const {return to_underlying(db.storage_of_data.freedom_keeper.get_used_count());}
377 static id_of_data get_at(size_t i) {return id_of_data(Record_Id(i));}
378 bool is_valid_at(size_t i) {return db.storage_of_data.freedom_keeper.is_used(Record_Id(i));}
379 id_of_data first() const {return *begin();}
380 id_of_data last() const {return *--end();}
381 id_of_data get_end() const {return *end();}
382 };
383
385 {
386 return container_of_data(*this);
387 }
388
389 template<class Comparator>
390 std::vector<id_of_data> Database::sorted_data(Comparator comparator) const
391 {
392 std::vector<id_of_data> result;
393 for (auto x: get_data_table())
394 result.emplace_back(x);
395 std::sort(result.begin(), result.end(), comparator);
396 return result;
397 }
398}
399
400#endif
Store all the tables of the database.
Definition Database.h:84
detail::data_of_data storage_of_data
Definition Database.h:104
detail::data_of_city storage_of_city
Definition Database.h:102
void internal_update_vector_data__city_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:153
void internal_update_vector_data__city(Record_Id record_id, size_t size, const id_of_city *value)
Definition Database.h:176
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:126
static void throw_exception(std::string_view message)
Definition Database.h:91
id_of_data previous(id_of_data id) const
Definition Database.h:248
void internal_update_data__population(Record_Id record_id, int64_t field_value_of_population)
Definition Database.h:189
void internal_delete_city(Record_Id record_id)
Definition Database.h:107
static id_of_data null_data()
Definition Database.h:259
std::vector< id_of_city > sorted_city(Comparator comparator) const
Definition Database.h:332
void internal_update_data__city(Record_Id record_id, id_of_city field_value_of_city)
Definition Database.h:166
std::vector< id_of_data > sorted_data(Comparator comparator) const
Definition Database.h:390
id_of_data next(id_of_data id) const
Definition Database.h:240
void internal_delete_data(Record_Id record_id)
Definition Database.h:112
bool is_valid(id_of_city id) const
Definition Database.h:98
container_of_data get_data_table() const
Definition Database.h:384
bool is_valid_record_id_for_data(Record_Id record_id) const
Definition Database.h:105
const std::string & get_city_name(id_of_data record) const
Definition Database.h:264
bool is_valid_record_id_for_city(Record_Id record_id) const
Definition Database.h:103
bool is_valid(id_of_data id) const
Definition Database.h:99
void internal_insert_data(Record_Id record_id)
Definition Database.h:131
static id_of_city null_city()
Definition Database.h:233
int64_t get_population(id_of_data record) const
Definition Database.h:276
id_of_city get_city(id_of_data record) const
Definition Database.h:270
id_of_city previous(id_of_city id) const
Definition Database.h:222
void internal_update_data__city_name(Record_Id record_id, std::string field_value_of_city_name)
Definition Database.h:143
void internal_update_vector_data__population(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:199
container_of_city get_city_table() const
Definition Database.h:326
void internal_vector_insert_data(Record_Id record_id, size_t size)
Definition Database.h:136
void internal_insert_city(Record_Id record_id)
Definition Database.h:121
id_of_city next(id_of_city id) const
Definition Database.h:214
returned by Database::get_city_table
Definition Database.h:284
static id_of_city get_at(size_t i)
Definition Database.h:319
returned by Database::get_data_table
Definition Database.h:342
static id_of_data get_at(size_t i)
Definition Database.h:377
Strongly-typed wrapper around an integer representing a row of the data table.
Definition ids.h:27
constexpr auto get_id() const
Definition ids.h:37
constexpr Record_Id get_record_id() const
Definition ids.h:38
#define JOEDB_RELEASE_ASSERT(x)
always-tested assertion (release and debug mode)
Definition assert.h:24
ptrdiff_t index_t
Definition index_types.h:18
constexpr const char * get_version()
Definition get_version.h:7
Automatically generated by joedbc.
Definition Client.h:19
tutorial::id_of_city id_of_city
Definition ids.h:23