Joedb 10.4.3
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/doc/source/tutorial/build/joedbc
7// Version: 10.4.3
8// joedbc compilation time: Jul 14 2026 13:07:22
9// Generation of this file: 2026-07-14 11:07:28 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
28
29static_assert(std::string_view(joedb::get_version()) == "10.4.3");
30
32{
33 /// @namespace tutorial::rpc::population
34 ///
35 /// Automatically generated by joedbc
36
37 using joedb::Record_Id;
38 using joedb::Table_Id;
39 using joedb::Field_Id;
40
41 class container_of_city;
42 class container_of_data;
43
44
45 namespace detail
46 {
47 struct data_of_city
48 {
49
50 joedb::Freedom_Keeper freedom_keeper;
51
52 size_t size() const {return freedom_keeper.size();}
53
54 void resize(size_t new_size)
55 {
56 freedom_keeper.resize(new_size);
57 }
58 };
59
60 struct data_of_data
61 {
62 std::vector<std::string> field_value_of_city_name;
63 std::vector<id_of_city> field_value_of_city;
64 std::vector<int64_t> field_value_of_population;
65
66 joedb::Freedom_Keeper freedom_keeper;
67
68 size_t size() const {return freedom_keeper.size();}
69
70 void resize(size_t new_size)
71 {
72 field_value_of_city_name.resize(new_size);
73 field_value_of_city.resize(new_size);
74 field_value_of_population.resize(new_size);
75 freedom_keeper.resize(new_size);
76 }
77 };
78 }
79
80
81 /// Store all the tables of the database
83 {
84 friend class Readable;
85 friend class container_of_city;
86 friend class container_of_data;
87
88 public:
89 template<typename E = joedb::Exception>
90 static void throw_exception(std::string_view message)
91 {
92 std::string s("tutorial::rpc::population: ");
93 s += message;
94 throw E(s);
95 }
96
97 bool is_valid(id_of_city id) const {return is_valid_record_id_for_city(id.get_record_id());}
98 bool is_valid(id_of_data id) const {return is_valid_record_id_for_data(id.get_record_id());}
99
100 protected:
101 detail::data_of_city storage_of_city;
102 bool is_valid_record_id_for_city(Record_Id record_id) const {return storage_of_city.freedom_keeper.is_used(record_id);}
103 detail::data_of_data storage_of_data;
104 bool is_valid_record_id_for_data(Record_Id record_id) const {return storage_of_data.freedom_keeper.is_used(record_id);}
105
107 {
109 storage_of_city.freedom_keeper.free(record_id);
110 }
112 {
114 storage_of_data.field_value_of_city_name[to_underlying(record_id)].clear();
115 storage_of_data.field_value_of_city[to_underlying(record_id)] = id_of_city(joedb::Record_Id::null);
116 storage_of_data.field_value_of_population[to_underlying(record_id)] = 0;
117 storage_of_data.freedom_keeper.free(record_id);
118 }
119
121 {
122 storage_of_city.freedom_keeper.use(record_id);
123 }
124
125 void internal_vector_insert_city(Record_Id record_id, size_t size)
126 {
127 JOEDB_RELEASE_ASSERT(storage_of_city.freedom_keeper.is_free_vector(record_id, size));
128 storage_of_city.freedom_keeper.use_vector(record_id, size);
129 }
131 {
132 storage_of_data.freedom_keeper.use(record_id);
133 }
134
135 void internal_vector_insert_data(Record_Id record_id, size_t size)
136 {
137 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_free_vector(record_id, size));
138 storage_of_data.freedom_keeper.use_vector(record_id, size);
139 }
140
142 (
143 Record_Id record_id,
144 std::string_view field_value_of_city_name
145 )
146 {
148 storage_of_data.field_value_of_city_name[to_underlying(record_id)] = field_value_of_city_name;
149 }
150
152 (
153 Record_Id record_id,
154 size_t size,
155 const std::string *value
156 )
157 {
158 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
159 std::string *target = &storage_of_data.field_value_of_city_name.data()[to_underlying(record_id)];
160 if (target != value)
161 std::copy_n(value, size, target);
162 }
163
165 (
166 Record_Id record_id,
167 id_of_city field_value_of_city
168 )
169 {
171 storage_of_data.field_value_of_city[to_underlying(record_id)] = field_value_of_city;
172 }
173
175 (
176 Record_Id record_id,
177 size_t size,
178 const id_of_city *value
179 )
180 {
181 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
182 id_of_city *target = &storage_of_data.field_value_of_city.data()[to_underlying(record_id)];
183 if (target != value)
184 std::copy_n(value, size, target);
185 }
186
188 (
189 Record_Id record_id,
190 int64_t field_value_of_population
191 )
192 {
194 storage_of_data.field_value_of_population[to_underlying(record_id)] = field_value_of_population;
195 }
196
198 (
199 Record_Id record_id,
200 size_t size,
201 const int64_t *value
202 )
203 {
204 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
205 int64_t *target = &storage_of_data.field_value_of_population.data()[to_underlying(record_id)];
206 if (target != value)
207 std::copy_n(value, size, target);
208 }
209
210 public:
212
214 {
215 return id_of_city
216 (
217 Record_Id(storage_of_city.freedom_keeper.get_next(id.get_record_id()))
218 );
219 }
220
222 {
223 return id_of_city
224 (
225 Record_Id(storage_of_city.freedom_keeper.get_previous(id.get_record_id()))
226 );
227 }
228
229 template<class Comparator>
230 std::vector<id_of_city> sorted_city(Comparator comparator) const;
231
233 {
234 return id_of_city();
235 }
236
238
240 {
241 return id_of_data
242 (
243 Record_Id(storage_of_data.freedom_keeper.get_next(id.get_record_id()))
244 );
245 }
246
248 {
249 return id_of_data
250 (
251 Record_Id(storage_of_data.freedom_keeper.get_previous(id.get_record_id()))
252 );
253 }
254
255 template<class Comparator>
256 std::vector<id_of_data> sorted_data(Comparator comparator) const;
257
259 {
260 return id_of_data();
261 }
262
263 const std::string & get_city_name(id_of_data record) const
264 {
266 return (const std::string &)(storage_of_data.field_value_of_city_name[record.get_id()]);
267 }
268
270 {
272 return (id_of_city)(storage_of_data.field_value_of_city[record.get_id()]);
273 }
274
275 int64_t get_population(id_of_data record) const
276 {
278 return (int64_t)(storage_of_data.field_value_of_population[record.get_id()]);
279 }
280 };
281 /// returned by @ref Database::get_city_table
283 {
284 friend class Database;
285
286 private:
287 const Database &db;
288 container_of_city(const Database &db): db(db) {}
289
290 public:
292 {
293 friend class container_of_city;
294 private:
295 const joedb::Freedom_Keeper *fk;
296 Record_Id index;
297 iterator(const detail::data_of_city &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
298 public:
299 using iterator_category = std::forward_iterator_tag;
301 using difference_type = std::ptrdiff_t;
304
305 bool operator==(const iterator &i) const {return index == i.index;}
306 bool operator!=(const iterator &i) const {return index != i.index;}
307 iterator &operator++() {index = fk->get_next(index); return *this;}
308 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
309 iterator &operator--() {index = fk->get_previous(index); return *this;}
310 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
311 id_of_city operator*() const {return id_of_city(Record_Id(index));}
312 };
313
314 iterator begin() const {return ++iterator(db.storage_of_city);}
315 iterator end() const {return iterator(db.storage_of_city);}
316 bool is_empty() const {return db.storage_of_city.freedom_keeper.get_used_count() == Record_Id{0};}
317 joedb::index_t get_size() const {return to_underlying(db.storage_of_city.freedom_keeper.get_used_count());}
318 static id_of_city get_at(size_t i) {return id_of_city(Record_Id(i));}
319 bool is_valid_at(size_t i) {return db.storage_of_city.freedom_keeper.is_used(Record_Id(i));}
320 id_of_city first() const {return *begin();}
321 id_of_city last() const {return *--end();}
322 id_of_city get_end() const {return *end();}
323 };
324
326 {
327 return container_of_city(*this);
328 }
329
330 template<class Comparator>
331 std::vector<id_of_city> Database::sorted_city(Comparator comparator) const
332 {
333 std::vector<id_of_city> result;
334 for (auto x: get_city_table())
335 result.emplace_back(x);
336 std::sort(result.begin(), result.end(), comparator);
337 return result;
338 }
339 /// returned by @ref Database::get_data_table
341 {
342 friend class Database;
343
344 private:
345 const Database &db;
346 container_of_data(const Database &db): db(db) {}
347
348 public:
350 {
351 friend class container_of_data;
352 private:
353 const joedb::Freedom_Keeper *fk;
354 Record_Id index;
355 iterator(const detail::data_of_data &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
356 public:
357 using iterator_category = std::forward_iterator_tag;
359 using difference_type = std::ptrdiff_t;
362
363 bool operator==(const iterator &i) const {return index == i.index;}
364 bool operator!=(const iterator &i) const {return index != i.index;}
365 iterator &operator++() {index = fk->get_next(index); return *this;}
366 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
367 iterator &operator--() {index = fk->get_previous(index); return *this;}
368 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
369 id_of_data operator*() const {return id_of_data(Record_Id(index));}
370 };
371
372 iterator begin() const {return ++iterator(db.storage_of_data);}
373 iterator end() const {return iterator(db.storage_of_data);}
374 bool is_empty() const {return db.storage_of_data.freedom_keeper.get_used_count() == Record_Id{0};}
375 joedb::index_t get_size() const {return to_underlying(db.storage_of_data.freedom_keeper.get_used_count());}
376 static id_of_data get_at(size_t i) {return id_of_data(Record_Id(i));}
377 bool is_valid_at(size_t i) {return db.storage_of_data.freedom_keeper.is_used(Record_Id(i));}
378 id_of_data first() const {return *begin();}
379 id_of_data last() const {return *--end();}
380 id_of_data get_end() const {return *end();}
381 };
382
384 {
385 return container_of_data(*this);
386 }
387
388 template<class Comparator>
389 std::vector<id_of_data> Database::sorted_data(Comparator comparator) const
390 {
391 std::vector<id_of_data> result;
392 for (auto x: get_data_table())
393 result.emplace_back(x);
394 std::sort(result.begin(), result.end(), comparator);
395 return result;
396 }
397}
398
399#endif
void resize(Record_Id new_size)
Record_Id get_previous(Record_Id index) const
Record_Id get_next(Record_Id index) const
static const Record_Id null
Definition index_types.h:44
Strongly-typed wrapper around an integer representing a row of the city table.
Definition ids.h:25
Store all the tables of the database.
Definition Database.h:83
detail::data_of_data storage_of_data
Definition Database.h:103
detail::data_of_city storage_of_city
Definition Database.h:101
void internal_update_vector_data__city_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:152
void internal_update_vector_data__city(Record_Id record_id, size_t size, const id_of_city *value)
Definition Database.h:175
void internal_update_data__city_name(Record_Id record_id, std::string_view field_value_of_city_name)
Definition Database.h:142
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:125
static void throw_exception(std::string_view message)
Definition Database.h:90
id_of_data previous(id_of_data id) const
Definition Database.h:247
void internal_update_data__population(Record_Id record_id, int64_t field_value_of_population)
Definition Database.h:188
void internal_delete_city(Record_Id record_id)
Definition Database.h:106
static id_of_data null_data()
Definition Database.h:258
std::vector< id_of_city > sorted_city(Comparator comparator) const
Definition Database.h:331
void internal_update_data__city(Record_Id record_id, id_of_city field_value_of_city)
Definition Database.h:165
std::vector< id_of_data > sorted_data(Comparator comparator) const
Definition Database.h:389
id_of_data next(id_of_data id) const
Definition Database.h:239
void internal_delete_data(Record_Id record_id)
Definition Database.h:111
bool is_valid(id_of_city id) const
Definition Database.h:97
container_of_data get_data_table() const
Definition Database.h:383
bool is_valid_record_id_for_data(Record_Id record_id) const
Definition Database.h:104
const std::string & get_city_name(id_of_data record) const
Definition Database.h:263
bool is_valid_record_id_for_city(Record_Id record_id) const
Definition Database.h:102
bool is_valid(id_of_data id) const
Definition Database.h:98
void internal_insert_data(Record_Id record_id)
Definition Database.h:130
static id_of_city null_city()
Definition Database.h:232
int64_t get_population(id_of_data record) const
Definition Database.h:275
id_of_city get_city(id_of_data record) const
Definition Database.h:269
id_of_city previous(id_of_city id) const
Definition Database.h:221
void internal_update_vector_data__population(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:198
container_of_city get_city_table() const
Definition Database.h:325
void internal_vector_insert_data(Record_Id record_id, size_t size)
Definition Database.h:135
void internal_insert_city(Record_Id record_id)
Definition Database.h:120
id_of_city next(id_of_city id) const
Definition Database.h:213
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
returned by Database::get_city_table
Definition Database.h:283
static id_of_city get_at(size_t i)
Definition Database.h:318
returned by Database::get_data_table
Definition Database.h:341
static id_of_data get_at(size_t i)
Definition Database.h:376
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