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 settings_Database_declared
13#define settings_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 settings
32{
33 /// @namespace settings
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_settings;
42
43
44 namespace detail
45 {
46 struct data_of_settings
47 {
48 Field_Id current_field_id = Field_Id(0);
49 std::vector<char> field_value_of_dark_mode;
50 std::vector<std::string> field_value_of_host;
51 std::vector<std::string> field_value_of_user;
52
53 joedb::Freedom_Keeper freedom_keeper;
54
55 size_t size() const {return freedom_keeper.size();}
56
57 void resize(size_t new_size)
58 {
59 field_value_of_dark_mode.resize(new_size);
60 field_value_of_host.resize(new_size);
61 field_value_of_user.resize(new_size);
62 freedom_keeper.resize(new_size);
63 }
64 };
65 }
66
67
68 /// Store all the tables of the database
70 {
71 friend class Readable;
73
74 public:
75 template<typename E = joedb::Exception>
76 static void throw_exception(std::string_view message)
77 {
78 std::string s("settings: ");
79 s += message;
80 throw E(s);
81 }
82
83 bool is_valid(id_of_settings id) const {return is_valid_record_id_for_settings(id.get_record_id());}
84
85 protected:
86 detail::data_of_settings storage_of_settings;
87 bool is_valid_record_id_for_settings(Record_Id record_id) const {return storage_of_settings.freedom_keeper.is_used(record_id);}
88
90 {
92 storage_of_settings.field_value_of_dark_mode[to_underlying(record_id)] = 0;
93 storage_of_settings.field_value_of_host[to_underlying(record_id)].clear();
94 storage_of_settings.field_value_of_user[to_underlying(record_id)].clear();
95 storage_of_settings.freedom_keeper.free(record_id);
96 }
97
99 {
100 storage_of_settings.freedom_keeper.use(record_id);
101 }
102
103 void internal_vector_insert_settings(Record_Id record_id, size_t size)
104 {
105 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_free_vector(record_id, size));
106 storage_of_settings.freedom_keeper.use_vector(record_id, size);
107 }
108
110 (
111 Record_Id record_id,
112 bool field_value_of_dark_mode
113 )
114 {
116 storage_of_settings.field_value_of_dark_mode[to_underlying(record_id)] = field_value_of_dark_mode;
117 }
118
120 (
121 Record_Id record_id,
122 size_t size,
123 const char *value
124 )
125 {
126 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
127 char *target = &storage_of_settings.field_value_of_dark_mode.data()[to_underlying(record_id)];
128 if (target != value)
129 std::copy_n(value, size, target);
130 }
131
133 (
134 Record_Id record_id,
135 std::string_view field_value_of_host
136 )
137 {
139 storage_of_settings.field_value_of_host[to_underlying(record_id)] = field_value_of_host;
140 }
141
143 (
144 Record_Id record_id,
145 size_t size,
146 const std::string *value
147 )
148 {
149 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
150 std::string *target = &storage_of_settings.field_value_of_host.data()[to_underlying(record_id)];
151 if (target != value)
152 std::copy_n(value, size, target);
153 }
154
156 (
157 Record_Id record_id,
158 std::string_view field_value_of_user
159 )
160 {
162 storage_of_settings.field_value_of_user[to_underlying(record_id)] = field_value_of_user;
163 }
164
166 (
167 Record_Id record_id,
168 size_t size,
169 const std::string *value
170 )
171 {
172 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
173 std::string *target = &storage_of_settings.field_value_of_user.data()[to_underlying(record_id)];
174 if (target != value)
175 std::copy_n(value, size, target);
176 }
177
178 public:
180
182 {
183 return id_of_settings
184 (
185 Record_Id(storage_of_settings.freedom_keeper.get_next(id.get_record_id()))
186 );
187 }
188
190 {
191 return id_of_settings
192 (
193 Record_Id(storage_of_settings.freedom_keeper.get_previous(id.get_record_id()))
194 );
195 }
196
198 {
199 return id_of_settings();
200 }
201 static constexpr id_of_settings the_settings()
202 {
203 return id_of_settings{0};
204 }
205
207 {
209 return (bool)(storage_of_settings.field_value_of_dark_mode[record.get_id()]);
210 }
211
212 const std::string & get_host(id_of_settings record = id_of_settings{0}) const
213 {
215 return (const std::string &)(storage_of_settings.field_value_of_host[record.get_id()]);
216 }
217
218 const std::string & get_user(id_of_settings record = id_of_settings{0}) const
219 {
221 return (const std::string &)(storage_of_settings.field_value_of_user[record.get_id()]);
222 }
223 };
224 /// returned by @ref Database::get_settings_table
226 {
227 friend class Database;
228
229 private:
230 const Database &db;
231 container_of_settings(const Database &db): db(db) {}
232
233 public:
235 {
237 private:
238 const joedb::Freedom_Keeper *fk;
239 Record_Id index;
240 iterator(const detail::data_of_settings &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
241 public:
242 using iterator_category = std::forward_iterator_tag;
244 using difference_type = std::ptrdiff_t;
247
248 bool operator==(const iterator &i) const {return index == i.index;}
249 bool operator!=(const iterator &i) const {return index != i.index;}
250 iterator &operator++() {index = fk->get_next(index); return *this;}
251 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
252 iterator &operator--() {index = fk->get_previous(index); return *this;}
253 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
255 };
256
259 bool is_empty() const {return db.storage_of_settings.freedom_keeper.get_used_count() == Record_Id{0};}
260 joedb::index_t get_size() const {return to_underlying(db.storage_of_settings.freedom_keeper.get_used_count());}
261 static id_of_settings get_at(size_t i) {return id_of_settings(Record_Id(i));}
262 bool is_valid_at(size_t i) {return db.storage_of_settings.freedom_keeper.is_used(Record_Id(i));}
263 id_of_settings first() const {return *begin();}
264 id_of_settings last() const {return *--end();}
265 id_of_settings get_end() const {return *end();}
266 };
267
269 {
270 return container_of_settings(*this);
271 }
272
273}
274
275#endif
void resize(Record_Id new_size)
Record_Id get_previous(Record_Id index) const
Record_Id get_next(Record_Id index) const
Store all the tables of the database.
Definition Database.h:70
bool is_valid_record_id_for_settings(Record_Id record_id) const
Definition Database.h:87
void internal_update_vector_settings__dark_mode(Record_Id record_id, size_t size, const char *value)
Definition Database.h:120
bool is_valid(id_of_settings id) const
Definition Database.h:83
static constexpr id_of_settings the_settings()
Definition Database.h:201
void internal_update_settings__dark_mode(Record_Id record_id, bool field_value_of_dark_mode)
Definition Database.h:110
void internal_insert_settings(Record_Id record_id)
Definition Database.h:98
static void throw_exception(std::string_view message)
Definition Database.h:76
friend class container_of_settings
Definition Database.h:72
void internal_vector_insert_settings(Record_Id record_id, size_t size)
Definition Database.h:103
void internal_update_settings__user(Record_Id record_id, std::string_view field_value_of_user)
Definition Database.h:156
void internal_delete_settings(Record_Id record_id)
Definition Database.h:89
static id_of_settings null_settings()
Definition Database.h:197
id_of_settings next(id_of_settings id) const
Definition Database.h:181
const std::string & get_host(id_of_settings record=id_of_settings{0}) const
Definition Database.h:212
void internal_update_vector_settings__user(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:166
bool get_dark_mode(id_of_settings record=id_of_settings{0}) const
Definition Database.h:206
void internal_update_settings__host(Record_Id record_id, std::string_view field_value_of_host)
Definition Database.h:133
const std::string & get_user(id_of_settings record=id_of_settings{0}) const
Definition Database.h:218
id_of_settings previous(id_of_settings id) const
Definition Database.h:189
void internal_update_vector_settings__host(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:143
detail::data_of_settings storage_of_settings
Definition Database.h:86
container_of_settings get_settings_table() const
Definition Database.h:268
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
bool operator==(const iterator &i) const
Definition Database.h:248
std::forward_iterator_tag iterator_category
Definition Database.h:242
bool operator!=(const iterator &i) const
Definition Database.h:249
returned by Database::get_settings_table
Definition Database.h:226
id_of_settings last() const
Definition Database.h:264
joedb::index_t get_size() const
Definition Database.h:260
static id_of_settings get_at(size_t i)
Definition Database.h:261
id_of_settings get_end() const
Definition Database.h:265
id_of_settings first() const
Definition Database.h:263
Strongly-typed wrapper around an integer representing a row of the settings table.
Definition ids.h:25
#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