Joedb 10.2.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.2.1
8// joedbc compilation time: Sep 15 2025 20:22:33
9// Generation of this file: 2025-09-15 18:23:01 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.2.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(const std::string &message)
75 {
76 throw E("settings: " + message);
77 }
78
79 bool is_valid(id_of_settings id) const {return is_valid_record_id_for_settings(id.get_record_id());}
80
81 protected:
82 detail::data_of_settings storage_of_settings;
83 bool is_valid_record_id_for_settings(Record_Id record_id) const {return storage_of_settings.freedom_keeper.is_used(record_id);}
84
86 {
88 storage_of_settings.field_value_of_dark_mode[to_underlying(record_id)] = 0;
89 storage_of_settings.field_value_of_host[to_underlying(record_id)].clear();
90 storage_of_settings.field_value_of_user[to_underlying(record_id)].clear();
91 storage_of_settings.freedom_keeper.free(record_id);
92 }
93
95 {
96 storage_of_settings.freedom_keeper.use(record_id);
97 }
98
99 void internal_vector_insert_settings(Record_Id record_id, size_t size)
100 {
101 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_free_vector(record_id, size));
102 storage_of_settings.freedom_keeper.use_vector(record_id, size);
103 }
104
106 (
107 Record_Id record_id,
108 bool field_value_of_dark_mode
109 )
110 {
112 storage_of_settings.field_value_of_dark_mode[to_underlying(record_id)] = field_value_of_dark_mode;
113 }
114
116 (
117 Record_Id record_id,
118 size_t size,
119 const char *value
120 )
121 {
122 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
123 char *target = &storage_of_settings.field_value_of_dark_mode.data()[to_underlying(record_id)];
124 if (target != value)
125 std::copy_n(value, size, target);
126 }
127
129 (
130 Record_Id record_id,
131 const std::string& field_value_of_host
132 )
133 {
135 storage_of_settings.field_value_of_host[to_underlying(record_id)] = field_value_of_host;
136 }
137
139 (
140 Record_Id record_id,
141 size_t size,
142 const std::string *value
143 )
144 {
145 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
146 std::string *target = &storage_of_settings.field_value_of_host.data()[to_underlying(record_id)];
147 if (target != value)
148 std::copy_n(value, size, target);
149 }
150
152 (
153 Record_Id record_id,
154 const std::string& field_value_of_user
155 )
156 {
158 storage_of_settings.field_value_of_user[to_underlying(record_id)] = field_value_of_user;
159 }
160
162 (
163 Record_Id record_id,
164 size_t size,
165 const std::string *value
166 )
167 {
168 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
169 std::string *target = &storage_of_settings.field_value_of_user.data()[to_underlying(record_id)];
170 if (target != value)
171 std::copy_n(value, size, target);
172 }
173
174 public:
176
178 {
179 return id_of_settings
180 (
181 Record_Id(storage_of_settings.freedom_keeper.get_next(id.get_record_id()))
182 );
183 }
184
186 {
187 return id_of_settings
188 (
189 Record_Id(storage_of_settings.freedom_keeper.get_previous(id.get_record_id()))
190 );
191 }
192
194 {
195 return id_of_settings();
196 }
197 static constexpr id_of_settings the_settings()
198 {
199 return id_of_settings{0};
200 }
201
203 {
205 return (bool)(storage_of_settings.field_value_of_dark_mode[record.get_id()]);
206 }
207
208 const std::string& get_host(id_of_settings record = id_of_settings{0}) const
209 {
211 return (const std::string&)(storage_of_settings.field_value_of_host[record.get_id()]);
212 }
213
214 const std::string& get_user(id_of_settings record = id_of_settings{0}) const
215 {
217 return (const std::string&)(storage_of_settings.field_value_of_user[record.get_id()]);
218 }
219 };
220 /// returned by @ref Database::get_settings_table
222 {
223 friend class Database;
224
225 private:
226 const Database &db;
227 container_of_settings(const Database &db): db(db) {}
228
229 public:
231 {
233 private:
234 const joedb::Freedom_Keeper *fk;
235 Record_Id index;
236 iterator(const detail::data_of_settings &data): fk(&data.freedom_keeper), index(joedb::Freedom_Keeper_Constants::used_list) {}
237 public:
238 using iterator_category = std::forward_iterator_tag;
240 using difference_type = std::ptrdiff_t;
243
244 bool operator==(const iterator &i) const {return index == i.index;}
245 bool operator!=(const iterator &i) const {return index != i.index;}
246 iterator &operator++() {index = fk->get_next(index); return *this;}
247 iterator operator++(int) {auto copy = *this; index = fk->get_next(index); return copy;}
248 iterator &operator--() {index = fk->get_previous(index); return *this;}
249 iterator operator--(int) {auto copy = *this; index = fk->get_previous(index); return copy;}
251 };
252
255 bool is_empty() const {return db.storage_of_settings.freedom_keeper.get_used_count() == Record_Id{0};}
256 joedb::index_t get_size() const {return to_underlying(db.storage_of_settings.freedom_keeper.get_used_count());}
257 static id_of_settings get_at(size_t i) {return id_of_settings(Record_Id(i));}
258 bool is_valid_at(size_t i) {return db.storage_of_settings.freedom_keeper.is_used(Record_Id(i));}
259 id_of_settings first() const {return *begin();}
260 id_of_settings last() const {return *--end();}
261 id_of_settings get_end() const {return *end();}
262 };
263
265 {
266 return container_of_settings(*this);
267 }
268
269}
270
271#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:83
void internal_update_vector_settings__dark_mode(Record_Id record_id, size_t size, const char *value)
Definition Database.h:116
bool is_valid(id_of_settings id) const
Definition Database.h:79
static constexpr id_of_settings the_settings()
Definition Database.h:197
void internal_update_settings__dark_mode(Record_Id record_id, bool field_value_of_dark_mode)
Definition Database.h:106
void internal_insert_settings(Record_Id record_id)
Definition Database.h:94
friend class container_of_settings
Definition Database.h:70
void internal_vector_insert_settings(Record_Id record_id, size_t size)
Definition Database.h:99
void internal_delete_settings(Record_Id record_id)
Definition Database.h:85
static id_of_settings null_settings()
Definition Database.h:193
id_of_settings next(id_of_settings id) const
Definition Database.h:177
const std::string & get_host(id_of_settings record=id_of_settings{0}) const
Definition Database.h:208
void internal_update_vector_settings__user(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:162
static void throw_exception(const std::string &message)
Definition Database.h:74
bool get_dark_mode(id_of_settings record=id_of_settings{0}) const
Definition Database.h:202
const std::string & get_user(id_of_settings record=id_of_settings{0}) const
Definition Database.h:214
id_of_settings previous(id_of_settings id) const
Definition Database.h:185
void internal_update_settings__host(Record_Id record_id, const std::string &field_value_of_host)
Definition Database.h:129
void internal_update_vector_settings__host(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:139
detail::data_of_settings storage_of_settings
Definition Database.h:82
void internal_update_settings__user(Record_Id record_id, const std::string &field_value_of_user)
Definition Database.h:152
container_of_settings get_settings_table() const
Definition Database.h:264
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
bool operator==(const iterator &i) const
Definition Database.h:244
std::forward_iterator_tag iterator_category
Definition Database.h:238
bool operator!=(const iterator &i) const
Definition Database.h:245
returned by Database::get_settings_table
Definition Database.h:222
id_of_settings last() const
Definition Database.h:260
joedb::index_t get_size() const
Definition Database.h:256
static id_of_settings get_at(size_t i)
Definition Database.h:257
id_of_settings get_end() const
Definition Database.h:261
id_of_settings first() const
Definition Database.h:259
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