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