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_city_Database_declared
13#define tutorial_rpc_city_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
31namespace tutorial::rpc::city
32{
33 /// @namespace tutorial::rpc::city
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
43
44 namespace detail
45 {
46 struct data_of_city
47 {
48 std::vector<std::string> field_value_of_name;
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 field_value_of_name.resize(new_size);
57 freedom_keeper.resize(new_size);
58 }
59 };
60 }
61
62
63 /// Store all the tables of the database
65 {
66 friend class Readable;
67 friend class container_of_city;
68
69 public:
70 template<typename E = joedb::Exception>
71 static void throw_exception(std::string_view message)
72 {
73 std::string s("tutorial::rpc::city: ");
74 s += message;
75 throw E(s);
76 }
77
78 bool is_valid(id_of_city id) const {return is_valid_record_id_for_city(id.get_record_id());}
79
80 protected:
81 detail::data_of_city storage_of_city;
82 bool is_valid_record_id_for_city(Record_Id record_id) const {return storage_of_city.freedom_keeper.is_used(record_id);}
83
85 {
87 storage_of_city.field_value_of_name[to_underlying(record_id)].clear();
88 storage_of_city.freedom_keeper.free(record_id);
89 }
90
92 {
93 storage_of_city.freedom_keeper.use(record_id);
94 }
95
96 void internal_vector_insert_city(Record_Id record_id, size_t size)
97 {
98 JOEDB_RELEASE_ASSERT(storage_of_city.freedom_keeper.is_free_vector(record_id, size));
99 storage_of_city.freedom_keeper.use_vector(record_id, size);
100 }
101
103 (
104 Record_Id record_id,
105 std::string_view field_value_of_name
106 )
107 {
109 storage_of_city.field_value_of_name[to_underlying(record_id)] = field_value_of_name;
110 }
111
113 (
114 Record_Id record_id,
115 size_t size,
116 const std::string *value
117 )
118 {
119 JOEDB_RELEASE_ASSERT(storage_of_city.freedom_keeper.is_used_vector(record_id, size));
120 std::string *target = &storage_of_city.field_value_of_name.data()[to_underlying(record_id)];
121 if (target != value)
122 std::copy_n(value, size, target);
123 }
124
125 public:
127
129 {
130 return id_of_city
131 (
132 Record_Id(storage_of_city.freedom_keeper.get_next(id.get_record_id()))
133 );
134 }
135
137 {
138 return id_of_city
139 (
140 Record_Id(storage_of_city.freedom_keeper.get_previous(id.get_record_id()))
141 );
142 }
143
145 {
146 return id_of_city();
147 }
148 static constexpr id_of_city the_city()
149 {
150 return id_of_city{0};
151 }
152
153 const std::string & get_name(id_of_city record = id_of_city{0}) const
154 {
155 JOEDB_RELEASE_ASSERT(is_valid_record_id_for_city(record.get_record_id()));
156 return (const std::string &)(storage_of_city.field_value_of_name[record.get_id()]);
157 }
158 };
159 /// returned by @ref Database::get_city_table
161 {
162 friend class Database;
163
164 private:
165 const Database &db;
166 container_of_city(const Database &db): db(db) {}
167
168 public:
170 {
171 friend class container_of_city;
172 private:
173 const joedb::Freedom_Keeper *fk;
174 Record_Id index;
175 iterator(const detail::data_of_city &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
176 public:
177 using iterator_category = std::forward_iterator_tag;
179 using difference_type = std::ptrdiff_t;
182
183 bool operator==(const iterator &i) const {return index == i.index;}
184 bool operator!=(const iterator &i) const {return index != i.index;}
185 iterator &operator++() {index = fk->get_next(index); return *this;}
186 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
187 iterator &operator--() {index = fk->get_previous(index); return *this;}
188 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
189 id_of_city operator*() const {return id_of_city(Record_Id(index));}
190 };
191
192 iterator begin() const {return ++iterator(db.storage_of_city);}
193 iterator end() const {return iterator(db.storage_of_city);}
194 bool is_empty() const {return db.storage_of_city.freedom_keeper.get_used_count() == Record_Id{0};}
195 joedb::index_t get_size() const {return to_underlying(db.storage_of_city.freedom_keeper.get_used_count());}
196 static id_of_city get_at(size_t i) {return id_of_city(Record_Id(i));}
197 bool is_valid_at(size_t i) {return db.storage_of_city.freedom_keeper.is_used(Record_Id(i));}
198 id_of_city first() const {return *begin();}
199 id_of_city last() const {return *--end();}
200 id_of_city get_end() const {return *end();}
201 };
202
204 {
205 return container_of_city(*this);
206 }
207
208}
209
210#endif
void resize(Record_Id new_size)
Record_Id get_previous(Record_Id index) const
Record_Id get_next(Record_Id index) const
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:65
friend class container_of_city
Definition Database.h:67
void internal_insert_city(Record_Id record_id)
Definition Database.h:91
static constexpr id_of_city the_city()
Definition Database.h:148
container_of_city get_city_table() const
Definition Database.h:203
const std::string & get_name(id_of_city record=id_of_city{0}) const
Definition Database.h:153
static id_of_city null_city()
Definition Database.h:144
bool is_valid_record_id_for_city(Record_Id record_id) const
Definition Database.h:82
id_of_city next(id_of_city id) const
Definition Database.h:128
static void throw_exception(std::string_view message)
Definition Database.h:71
bool is_valid(id_of_city id) const
Definition Database.h:78
detail::data_of_city storage_of_city
Definition Database.h:81
void internal_vector_insert_city(Record_Id record_id, size_t size)
Definition Database.h:96
void internal_update_city__name(Record_Id record_id, std::string_view field_value_of_name)
Definition Database.h:103
void internal_delete_city(Record_Id record_id)
Definition Database.h:84
id_of_city previous(id_of_city id) const
Definition Database.h:136
void internal_update_vector_city__name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:113
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
std::forward_iterator_tag iterator_category
Definition Database.h:177
bool operator==(const iterator &i) const
Definition Database.h:183
bool operator!=(const iterator &i) const
Definition Database.h:184
returned by Database::get_city_table
Definition Database.h:161
static id_of_city get_at(size_t i)
Definition Database.h:196
joedb::index_t get_size() const
Definition Database.h:195
#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