Joedb 10.2.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.2.1
8// joedbc compilation time: Sep 15 2025 20:22:33
9// Generation of this file: 2025-09-15 18:23:01 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.2.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(const std::string &message)
89 {
90 throw E("tutorial::rpc::population: " + message);
91 }
92
93 bool is_valid(id_of_city id) const {return is_valid_record_id_for_city(id.get_record_id());}
94 bool is_valid(id_of_data id) const {return is_valid_record_id_for_data(id.get_record_id());}
95
96 protected:
97 detail::data_of_city storage_of_city;
98 bool is_valid_record_id_for_city(Record_Id record_id) const {return storage_of_city.freedom_keeper.is_used(record_id);}
99 detail::data_of_data storage_of_data;
100 bool is_valid_record_id_for_data(Record_Id record_id) const {return storage_of_data.freedom_keeper.is_used(record_id);}
101
103 {
105 storage_of_city.freedom_keeper.free(record_id);
106 }
108 {
110 storage_of_data.field_value_of_city_name[to_underlying(record_id)].clear();
111 storage_of_data.field_value_of_city[to_underlying(record_id)] = id_of_city(joedb::Record_Id::null);
112 storage_of_data.field_value_of_population[to_underlying(record_id)] = 0;
113 storage_of_data.freedom_keeper.free(record_id);
114 }
115
117 {
118 storage_of_city.freedom_keeper.use(record_id);
119 }
120
121 void internal_vector_insert_city(Record_Id record_id, size_t size)
122 {
123 JOEDB_RELEASE_ASSERT(storage_of_city.freedom_keeper.is_free_vector(record_id, size));
124 storage_of_city.freedom_keeper.use_vector(record_id, size);
125 }
127 {
128 storage_of_data.freedom_keeper.use(record_id);
129 }
130
131 void internal_vector_insert_data(Record_Id record_id, size_t size)
132 {
133 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_free_vector(record_id, size));
134 storage_of_data.freedom_keeper.use_vector(record_id, size);
135 }
136
138 (
139 Record_Id record_id,
140 const std::string& field_value_of_city_name
141 )
142 {
144 storage_of_data.field_value_of_city_name[to_underlying(record_id)] = field_value_of_city_name;
145 }
146
148 (
149 Record_Id record_id,
150 size_t size,
151 const std::string *value
152 )
153 {
154 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
155 std::string *target = &storage_of_data.field_value_of_city_name.data()[to_underlying(record_id)];
156 if (target != value)
157 std::copy_n(value, size, target);
158 }
159
161 (
162 Record_Id record_id,
163 id_of_city field_value_of_city
164 )
165 {
167 storage_of_data.field_value_of_city[to_underlying(record_id)] = field_value_of_city;
168 }
169
171 (
172 Record_Id record_id,
173 size_t size,
174 const id_of_city *value
175 )
176 {
177 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
178 id_of_city *target = &storage_of_data.field_value_of_city.data()[to_underlying(record_id)];
179 if (target != value)
180 std::copy_n(value, size, target);
181 }
182
184 (
185 Record_Id record_id,
186 int64_t field_value_of_population
187 )
188 {
190 storage_of_data.field_value_of_population[to_underlying(record_id)] = field_value_of_population;
191 }
192
194 (
195 Record_Id record_id,
196 size_t size,
197 const int64_t *value
198 )
199 {
200 JOEDB_RELEASE_ASSERT(storage_of_data.freedom_keeper.is_used_vector(record_id, size));
201 int64_t *target = &storage_of_data.field_value_of_population.data()[to_underlying(record_id)];
202 if (target != value)
203 std::copy_n(value, size, target);
204 }
205
206 public:
208
210 {
211 return id_of_city
212 (
213 Record_Id(storage_of_city.freedom_keeper.get_next(id.get_record_id()))
214 );
215 }
216
218 {
219 return id_of_city
220 (
221 Record_Id(storage_of_city.freedom_keeper.get_previous(id.get_record_id()))
222 );
223 }
224
225 template<class Comparator>
226 std::vector<id_of_city> sorted_city(Comparator comparator) const;
227
229 {
230 return id_of_city();
231 }
232
234
236 {
237 return id_of_data
238 (
239 Record_Id(storage_of_data.freedom_keeper.get_next(id.get_record_id()))
240 );
241 }
242
244 {
245 return id_of_data
246 (
247 Record_Id(storage_of_data.freedom_keeper.get_previous(id.get_record_id()))
248 );
249 }
250
251 template<class Comparator>
252 std::vector<id_of_data> sorted_data(Comparator comparator) const;
253
255 {
256 return id_of_data();
257 }
258
259 const std::string& get_city_name(id_of_data record) const
260 {
262 return (const std::string&)(storage_of_data.field_value_of_city_name[record.get_id()]);
263 }
264
266 {
268 return (id_of_city)(storage_of_data.field_value_of_city[record.get_id()]);
269 }
270
271 int64_t get_population(id_of_data record) const
272 {
274 return (int64_t)(storage_of_data.field_value_of_population[record.get_id()]);
275 }
276 };
277 /// returned by @ref Database::get_city_table
279 {
280 friend class Database;
281
282 private:
283 const Database &db;
284 container_of_city(const Database &db): db(db) {}
285
286 public:
288 {
289 friend class container_of_city;
290 private:
291 const joedb::Freedom_Keeper *fk;
292 Record_Id index;
293 iterator(const detail::data_of_city &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
294 public:
295 using iterator_category = std::forward_iterator_tag;
297 using difference_type = std::ptrdiff_t;
300
301 bool operator==(const iterator &i) const {return index == i.index;}
302 bool operator!=(const iterator &i) const {return index != i.index;}
303 iterator &operator++() {index = fk->get_next(index); return *this;}
304 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
305 iterator &operator--() {index = fk->get_previous(index); return *this;}
306 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
307 id_of_city operator*() const {return id_of_city(Record_Id(index));}
308 };
309
310 iterator begin() const {return ++iterator(db.storage_of_city);}
311 iterator end() const {return iterator(db.storage_of_city);}
312 bool is_empty() const {return db.storage_of_city.freedom_keeper.get_used_count() == Record_Id{0};}
313 joedb::index_t get_size() const {return to_underlying(db.storage_of_city.freedom_keeper.get_used_count());}
314 static id_of_city get_at(size_t i) {return id_of_city(Record_Id(i));}
315 bool is_valid_at(size_t i) {return db.storage_of_city.freedom_keeper.is_used(Record_Id(i));}
316 id_of_city first() const {return *begin();}
317 id_of_city last() const {return *--end();}
318 id_of_city get_end() const {return *end();}
319 };
320
322 {
323 return container_of_city(*this);
324 }
325
326 template<class Comparator>
327 std::vector<id_of_city> Database::sorted_city(Comparator comparator) const
328 {
329 std::vector<id_of_city> result;
330 for (auto x: get_city_table())
331 result.emplace_back(x);
332 std::sort(result.begin(), result.end(), comparator);
333 return result;
334 }
335 /// returned by @ref Database::get_data_table
337 {
338 friend class Database;
339
340 private:
341 const Database &db;
342 container_of_data(const Database &db): db(db) {}
343
344 public:
346 {
347 friend class container_of_data;
348 private:
349 const joedb::Freedom_Keeper *fk;
350 Record_Id index;
351 iterator(const detail::data_of_data &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
352 public:
353 using iterator_category = std::forward_iterator_tag;
355 using difference_type = std::ptrdiff_t;
358
359 bool operator==(const iterator &i) const {return index == i.index;}
360 bool operator!=(const iterator &i) const {return index != i.index;}
361 iterator &operator++() {index = fk->get_next(index); return *this;}
362 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
363 iterator &operator--() {index = fk->get_previous(index); return *this;}
364 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
365 id_of_data operator*() const {return id_of_data(Record_Id(index));}
366 };
367
368 iterator begin() const {return ++iterator(db.storage_of_data);}
369 iterator end() const {return iterator(db.storage_of_data);}
370 bool is_empty() const {return db.storage_of_data.freedom_keeper.get_used_count() == Record_Id{0};}
371 joedb::index_t get_size() const {return to_underlying(db.storage_of_data.freedom_keeper.get_used_count());}
372 static id_of_data get_at(size_t i) {return id_of_data(Record_Id(i));}
373 bool is_valid_at(size_t i) {return db.storage_of_data.freedom_keeper.is_used(Record_Id(i));}
374 id_of_data first() const {return *begin();}
375 id_of_data last() const {return *--end();}
376 id_of_data get_end() const {return *end();}
377 };
378
380 {
381 return container_of_data(*this);
382 }
383
384 template<class Comparator>
385 std::vector<id_of_data> Database::sorted_data(Comparator comparator) const
386 {
387 std::vector<id_of_data> result;
388 for (auto x: get_data_table())
389 result.emplace_back(x);
390 std::sort(result.begin(), result.end(), comparator);
391 return result;
392 }
393}
394
395#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:99
detail::data_of_city storage_of_city
Definition Database.h:97
void internal_update_vector_data__city_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:148
void internal_update_vector_data__city(Record_Id record_id, size_t size, const id_of_city *value)
Definition Database.h:171
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:121
id_of_data previous(id_of_data id) const
Definition Database.h:243
void internal_update_data__population(Record_Id record_id, int64_t field_value_of_population)
Definition Database.h:184
void internal_delete_city(Record_Id record_id)
Definition Database.h:102
static id_of_data null_data()
Definition Database.h:254
std::vector< id_of_city > sorted_city(Comparator comparator) const
Definition Database.h:327
void internal_update_data__city(Record_Id record_id, id_of_city field_value_of_city)
Definition Database.h:161
std::vector< id_of_data > sorted_data(Comparator comparator) const
Definition Database.h:385
id_of_data next(id_of_data id) const
Definition Database.h:235
void internal_delete_data(Record_Id record_id)
Definition Database.h:107
bool is_valid(id_of_city id) const
Definition Database.h:93
void internal_update_data__city_name(Record_Id record_id, const std::string &field_value_of_city_name)
Definition Database.h:138
container_of_data get_data_table() const
Definition Database.h:379
bool is_valid_record_id_for_data(Record_Id record_id) const
Definition Database.h:100
const std::string & get_city_name(id_of_data record) const
Definition Database.h:259
bool is_valid_record_id_for_city(Record_Id record_id) const
Definition Database.h:98
bool is_valid(id_of_data id) const
Definition Database.h:94
void internal_insert_data(Record_Id record_id)
Definition Database.h:126
static id_of_city null_city()
Definition Database.h:228
int64_t get_population(id_of_data record) const
Definition Database.h:271
id_of_city get_city(id_of_data record) const
Definition Database.h:265
id_of_city previous(id_of_city id) const
Definition Database.h:217
void internal_update_vector_data__population(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:194
static void throw_exception(const std::string &message)
Definition Database.h:88
container_of_city get_city_table() const
Definition Database.h:321
void internal_vector_insert_data(Record_Id record_id, size_t size)
Definition Database.h:131
void internal_insert_city(Record_Id record_id)
Definition Database.h:116
id_of_city next(id_of_city id) const
Definition Database.h:209
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
returned by Database::get_city_table
Definition Database.h:279
static id_of_city get_at(size_t i)
Definition Database.h:314
returned by Database::get_data_table
Definition Database.h:337
static id_of_data get_at(size_t i)
Definition Database.h:372
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