13 Generator(
".",
"Writable_Database.h", options)
27 out <<
"\n#include \"joedb/Span.h\"\n";
30#include "Database_Writable.h"
47 class Memory_Database;
50 class Writable_Database: public Database_Writable
52 friend class detail::Client_Data;
54 friend class Multiplexer;
55 friend class Memory_Database;
58 joedb::Writable_Journal journal;
63 void check_single_row();
71 void custom(const std::string &name) override
73 Database_Writable::custom(name);
80 out <<
" if (name == \"" << name <<
"\")\n";
81 out <<
" " << name <<
"(*this);\n";
89 out <<
" static void " << name <<
"(Writable_Database &db);\n";
99 const std::string &name,
107 out <<
"\n void create_table(const std::string &name) override;\n";
113 joedb::Abstract_File &file,
114 joedb::Recovery recovery,
115 bool perform_initialization
119 Writable_Database(joedb::Abstract_File &file);
123 joedb::Abstract_File &file,
124 joedb::Recovery recovery
127 const joedb::Readonly_Journal &get_journal() const {return journal;}
129 std::string read_blob(joedb::Blob blob) const
131 return journal.get_file().read_blob(blob);
134 joedb::Blob write_blob(std::string_view data) override
136 return journal.write_blob(data);
139 int64_t ahead_of_checkpoint() const
141 return journal.ahead_of_checkpoint();
144 void soft_checkpoint() override
146 journal.soft_checkpoint();
149 void hard_checkpoint() override
151 journal.hard_checkpoint();
154 void write_comment(const std::string &comment);
155 void write_timestamp();
156 void write_timestamp(int64_t timestamp);
157 void write_valid_data();
158 void flush() override {journal.flush();}
161 for (
const auto &[tid, tname]: tables)
171 out <<
" void clear_" << tname <<
"_table();\n";
176 out <<
" private:\n";
181 out <<
" id_of_" << tname <<
" new_" << tname <<
"()\n";
184 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname <<
".freedom_keeper.get_free_record()));\n";
185 out <<
" storage_of_" << tname <<
".resize(storage_of_" << tname <<
".freedom_keeper.size());\n";
186 out <<
" internal_insert_" << tname <<
"(result.get_record_id());\n\n";
187 out <<
" journal.insert_into(Table_Id(" << tid <<
"), result.get_record_id());\n";
188 out <<
" return result;\n";
191 out <<
" void insert_" << tname <<
"(id_of_" << tname <<
" id)\n";
193 out <<
" if (id.get_record_id() >= Record_Id(storage_of_" << tname <<
".size()))\n";
194 out <<
" storage_of_" << tname <<
".resize(id.get_id() + 1);\n";
195 out <<
" internal_insert_" << tname <<
"(id.get_record_id());\n";
196 out <<
" journal.insert_into(Table_Id(" << tid <<
"), id.get_record_id());\n";
204 out <<
" id_of_" << tname <<
" new_vector_of_" << tname <<
"(size_t size)\n";
206 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname;
207 out <<
".size()));\n";
208 out <<
" storage_of_" << tname <<
".resize(storage_of_";
209 out << tname <<
".size() + size);\n";
210 out <<
" internal_vector_insert_" << tname <<
"(result.get_record_id(), size);\n";
211 out <<
" journal.insert_vector(Table_Id(" << tid;
212 out <<
"), result.get_record_id(), size);\n";
213 out <<
" return result;\n";
223 out <<
" id_of_" << tname <<
" new_" << tname <<
'\n';
228 for (
const auto &[fid, fname]: db.
get_fields(tid))
237 out <<
" field_value_of_" << fname;
244 out <<
" auto result = new_" << tname <<
"();\n";
246 for (
const auto &[fid, fname]: db.
get_fields(tid))
247 out <<
" set_" << fname <<
"(result, field_value_of_" << fname <<
");\n";
249 out <<
" return result;\n";
261 out <<
" void delete_" << tname <<
"(id_of_" << tname <<
" record)\n";
263 out <<
" internal_delete_" << tname <<
"(record.get_record_id());\n";
264 out <<
" journal.delete_from(Table_Id(" << tid <<
"), record.get_record_id());\n";
267 out <<
" void delete_vector_of_" << tname <<
"(id_of_" << tname <<
" v, size_t size)\n";
269 out <<
" for (size_t i = size; i > 0;)\n";
270 out <<
" internal_delete_" << tname <<
"(v[--i].get_record_id());\n";
271 out <<
" journal.delete_vector(Table_Id(" << tid <<
"), v.get_record_id(), size);\n";
278 for (
const auto &[fid, fname]: db.
get_fields(tid))
285 out <<
" void set_" << fname;
286 out <<
"(id_of_" << tname <<
" record, ";
288 out <<
" field_value_of_" << fname <<
")\n";
290 out <<
" internal_update_" << tname <<
"__" << fname;
292 out <<
"(record.get_record_id(), ";
293 out <<
"field_value_of_" << fname <<
");\n";
294 out <<
" journal.update_";
296 out <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), ";
297 out <<
"field_value_of_" << fname;
298 if (type.
get_type_id() == Type::Type_Id::reference)
299 out <<
".get_record_id()";
305 out <<
" void set_" << fname;
308 out <<
" field_value_of_" << fname <<
")\n";
310 out <<
" set_" << fname <<
"(the_" << tname;
311 out <<
"(), field_value_of_" << fname <<
");\n";
320 out <<
" template<typename F> void update_vector_of_" << fname;
321 out <<
"(id_of_" << tname <<
" record, size_t size, F f)\n";
323 out <<
" joedb::Span<";
325 out <<
"> span(&storage_of_" << tname;
326 out <<
".field_value_of_" << fname <<
".data()[record.get_id()], size);\n";
327 out <<
" f(span);\n";
328 out <<
" internal_update_vector_" << tname <<
"__" << fname <<
"(record.get_record_id(), size, span.begin());\n";
329 out <<
" journal.update_vector_" <<
get_type_string(type) <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), size, ";
331 if (type.
get_type_id() == Type::Type_Id::reference)
332 out <<
"reinterpret_cast<Record_Id *>";
334 out <<
"(span.begin()));\n";
const std::vector< std::string > & get_custom_names() const
const std::vector< std::string > & get_name_space() const
bool is_unique_field_name(const std::string &field_name) const
bool has_single_row() const
const Table_Options & get_table_options(Table_Id table_id) const
const Database & get_db() const
bool has_multi_row() const
const std::map< Table_Id, std::string > & get_tables() const override
const Type & get_field_type(Table_Id table_id, Field_Id field_id) const override
const std::map< Field_Id, std::string > & get_fields(Table_Id table_id) const override
Type_Id get_type_id() const
static const char * get_type_string(Type type)
const Compiler_Options & options
bool db_has_values() const
void write_type(std::ostream &out, Type type, bool return_type, bool setter_type)
Writable_Database_h(const Compiler_Options &options)
void write(std::ostream &out) override
void namespace_open(std::ostream &out, const std::vector< std::string > &n)
void namespace_close(std::ostream &out, const std::vector< std::string > &n)
void namespace_include_guard_open(std::ostream &out, const char *name, const std::vector< std::string > &n)
void namespace_include_guard_close(std::ostream &out)
One code generator for each of the file generated by joedbc.