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