29#include "joedb/interpreted/Database_Schema.h"
30#include "joedb/journal/Readonly_Memory_File.h"
41 class Readable: public joedb::Database_Schema
47 Readable(const Database &db): db(db)
49 joedb::Readonly_Memory_File file(detail::schema_string, detail::schema_string_size);
50 joedb::Readonly_Journal journal(file);
51 journal.replay_log(*this);
54 const joedb::Compact_Freedom_Keeper &get_freedom
61 for (
const auto &[tid, tname]: tables)
64 out <<
" return db.storage_of_" << tname <<
".freedom_keeper;\n";
68 throw joedb::Exception("unknown table_id");
73 for (
int type_index = 1; type_index < int(
Type::type_ids); type_index++)
89 for (
const auto &[tid, tname]: tables)
91 bool has_typed_field =
false;
93 for (
const auto &[fid, fname]: db.
get_fields(tid))
98 has_typed_field =
true;
108 for (
const auto &[fid, fname]: db.
get_fields(tid))
114 out <<
" if (field_id == Field_Id(" << fid <<
"))\n";
118 if (type_id == joedb::Type::Type_Id::reference)
119 out <<
"*reinterpret_cast<const joedb::Record_Id *>(&";
121 out <<
"db.storage_of_" << tname <<
".field_value_of_" << fname <<
"[size_t(record_id) - 1]";
123 if (type_id == joedb::Type::Type_Id::reference)
136 throw joedb::Exception("unknown field");
143 for (
const auto &[tid, tname]: tables)
145 out <<
"\n namespace interpreted_" << tname <<
'\n';
147 out <<
" constexpr static Table_Id table_id = Table_Id{" << int(tid) <<
"};\n";
148 for (
const auto &[fid, fname]: db.
get_fields(tid))
149 out <<
" constexpr static Field_Id " << fname <<
"_field_id = Field_Id{" <<
int(fid) <<
"};\n";
const std::vector< std::string > & get_name_space() const
const Database & get_db() 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_storage_type_string(Type type)
static const char * get_type_string(Type type)
const Compiler_Options & options
Readable_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(std::ostream &out, const char *name, const std::vector< std::string > &n)
One code generator for each of the file generated by joedbc.
constexpr std::underlying_type< Table_Id >::type to_underlying(Table_Id id)