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