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