Joedb 10.0.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.0.1
8// joedbc compilation time: Jun 13 2025 15:26:57
9// Generation of this file: 2025-06-13 13:27:16 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.0.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;
70 friend class id_of_settings;
72
73 public:
74 template<typename E = joedb::Exception>
75 static void throw_exception(const std::string &message)
76 {
77 throw E("settings: " + message);
78 }
79
80 bool is_valid(id_of_settings id) const {return is_valid_record_id_for_settings(id.get_record_id());}
81
82 protected:
83 detail::data_of_settings storage_of_settings;
84 bool is_valid_record_id_for_settings(Record_Id record_id) const {return storage_of_settings.freedom_keeper.is_used(record_id);}
85
87 {
89 storage_of_settings.field_value_of_dark_mode[to_underlying(record_id)] = 0;
90 storage_of_settings.field_value_of_host[to_underlying(record_id)].clear();
91 storage_of_settings.field_value_of_user[to_underlying(record_id)].clear();
92 storage_of_settings.freedom_keeper.free(record_id);
93 }
94
96 {
97 storage_of_settings.freedom_keeper.use(record_id);
98 }
99
100 void internal_vector_insert_settings(Record_Id record_id, size_t size)
101 {
102 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_free_vector(record_id, size));
103 storage_of_settings.freedom_keeper.use_vector(record_id, size);
104 }
105
107 (
108 Record_Id record_id,
109 bool field_value_of_dark_mode
110 )
111 {
113 storage_of_settings.field_value_of_dark_mode[to_underlying(record_id)] = field_value_of_dark_mode;
114 }
115
117 (
118 Record_Id record_id,
119 size_t size,
120 const char *value
121 )
122 {
123 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
124 char *target = &storage_of_settings.field_value_of_dark_mode.data()[to_underlying(record_id)];
125 if (target != value)
126 std::copy_n(value, size, target);
127 }
128
130 (
131 Record_Id record_id,
132 const std::string& field_value_of_host
133 )
134 {
136 storage_of_settings.field_value_of_host[to_underlying(record_id)] = field_value_of_host;
137 }
138
140 (
141 Record_Id record_id,
142 size_t size,
143 const std::string *value
144 )
145 {
146 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
147 std::string *target = &storage_of_settings.field_value_of_host.data()[to_underlying(record_id)];
148 if (target != value)
149 std::copy_n(value, size, target);
150 }
151
153 (
154 Record_Id record_id,
155 const std::string& field_value_of_user
156 )
157 {
159 storage_of_settings.field_value_of_user[to_underlying(record_id)] = field_value_of_user;
160 }
161
163 (
164 Record_Id record_id,
165 size_t size,
166 const std::string *value
167 )
168 {
169 JOEDB_RELEASE_ASSERT(storage_of_settings.freedom_keeper.is_used_vector(record_id, size));
170 std::string *target = &storage_of_settings.field_value_of_user.data()[to_underlying(record_id)];
171 if (target != value)
172 std::copy_n(value, size, target);
173 }
174
175 public:
177
179 {
180 return id_of_settings
181 (
182 Record_Id(storage_of_settings.freedom_keeper.get_next(id.get_record_id()))
183 );
184 }
185
187 {
188 return id_of_settings
189 (
190 Record_Id(storage_of_settings.freedom_keeper.get_previous(id.get_record_id()))
191 );
192 }
193
194 template<class Comparator>
195 std::vector<id_of_settings> sorted_settings(Comparator comparator) const;
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 typedef std::forward_iterator_tag iterator_category;
244 typedef std::ptrdiff_t difference_type;
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 template<class Comparator>
274 std::vector<id_of_settings> Database::sorted_settings(Comparator comparator) const
275 {
276 std::vector<id_of_settings> result;
277 for (auto x: get_settings_table())
278 result.emplace_back(x);
279 std::sort(result.begin(), result.end(), comparator);
280 return result;
281 }
282}
283
284#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:84
void internal_update_vector_settings__dark_mode(Record_Id record_id, size_t size, const char *value)
Definition Database.h:117
bool is_valid(id_of_settings id) const
Definition Database.h:80
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:107
void internal_insert_settings(Record_Id record_id)
Definition Database.h:95
friend class id_of_settings
Definition Database.h:70
std::vector< id_of_settings > sorted_settings(Comparator comparator) const
Definition Database.h:274
friend class container_of_settings
Definition Database.h:71
void internal_vector_insert_settings(Record_Id record_id, size_t size)
Definition Database.h:100
void internal_delete_settings(Record_Id record_id)
Definition Database.h:86
static id_of_settings null_settings()
Definition Database.h:197
id_of_settings next(id_of_settings id) const
Definition Database.h:178
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:163
static void throw_exception(const std::string &message)
Definition Database.h:75
bool get_dark_mode(id_of_settings record=id_of_settings{0}) const
Definition Database.h:206
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:186
void internal_update_settings__host(Record_Id record_id, const std::string &field_value_of_host)
Definition Database.h:130
void internal_update_vector_settings__host(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:140
detail::data_of_settings storage_of_settings
Definition Database.h:83
void internal_update_settings__user(Record_Id record_id, const std::string &field_value_of_user)
Definition Database.h:153
container_of_settings get_settings_table() const
Definition Database.h:268
Implement the joedb::Readable interface for a compiled database.
Definition Readable.h:27
std::forward_iterator_tag iterator_category
Definition Database.h:242
bool operator==(const iterator &i) const
Definition Database.h:248
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
Definition Blob.h:7
Automatically generated by joedbc.
Definition Client.h:19