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