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(const std::string &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";
197 out <<
" id_of_" << tname <<
" new_vector_of_" << tname <<
"(size_t size)\n";
199 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname;
200 out <<
".size()));\n";
201 out <<
" storage_of_" << tname <<
".resize(storage_of_";
202 out << tname <<
".size() + size);\n";
203 out <<
" internal_vector_insert_" << tname <<
"(result.get_record_id(), size);\n";
204 out <<
" journal.insert_vector(Table_Id(" << tid;
205 out <<
"), result.get_record_id(), size);\n";
206 out <<
" return result;\n";
216 out <<
" id_of_" << tname <<
" new_" << tname <<
'\n';
221 for (
const auto &[fid, fname]: db.
get_fields(tid))
230 out <<
" field_value_of_" << fname;
237 out <<
" auto result = new_" << tname <<
"();\n";
239 for (
const auto &[fid, fname]: db.
get_fields(tid))
240 out <<
" set_" << fname <<
"(result, field_value_of_" << fname <<
");\n";
242 out <<
" return result;\n";
254 out <<
" void delete_" << tname <<
"(id_of_" << tname <<
" record)\n";
256 out <<
" internal_delete_" << tname <<
"(record.get_record_id());\n";
257 out <<
" journal.delete_from(Table_Id(" << tid <<
"), record.get_record_id());\n";
260 out <<
" void delete_vector_of_" << tname <<
"(id_of_" << tname <<
" v, size_t size)\n";
262 out <<
" for (size_t i = size; i > 0;)\n";
263 out <<
" internal_delete_" << tname <<
"(v[--i].get_record_id());\n";
264 out <<
" journal.delete_vector(Table_Id(" << tid <<
"), v.get_record_id(), size);\n";
271 for (
const auto &[fid, fname]: db.
get_fields(tid))
278 out <<
" void set_" << fname;
279 out <<
"(id_of_" << tname <<
" record, ";
281 out <<
" field_value_of_" << fname <<
")\n";
283 out <<
" internal_update_" << tname <<
"__" << fname;
285 out <<
"(record.get_record_id(), ";
286 out <<
"field_value_of_" << fname <<
");\n";
287 out <<
" journal.update_";
289 out <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), ";
290 out <<
"field_value_of_" << fname;
291 if (type.
get_type_id() == Type::Type_Id::reference)
292 out <<
".get_record_id()";
298 out <<
" void set_" << fname;
301 out <<
" field_value_of_" << fname <<
")\n";
303 out <<
" set_" << fname <<
"(the_" << tname;
304 out <<
"(), field_value_of_" << fname <<
");\n";
313 out <<
" template<typename F> void update_vector_of_" << fname;
314 out <<
"(id_of_" << tname <<
" record, size_t size, F f)\n";
316 out <<
" joedb::Span<";
318 out <<
"> span(&storage_of_" << tname;
319 out <<
".field_value_of_" << fname <<
".data()[record.get_id()], size);\n";
320 out <<
" f(span);\n";
321 out <<
" internal_update_vector_" << tname <<
"__" << fname <<
"(record.get_record_id(), size, span.begin());\n";
322 out <<
" journal.update_vector_" <<
get_type_string(type) <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), size, ";
324 if (type.
get_type_id() == Type::Type_Id::reference)
325 out <<
"reinterpret_cast<Record_Id *>";
327 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)
void write_type(Type type, bool return_type, bool setter_type)
const Compiler_Options & options
bool db_has_values() const
Writable_Database_h(const Compiler_Options &options)
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.