Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
introspection_h.cpp
Go to the documentation of this file.
4
5namespace joedb::generator
6{
7 ////////////////////////////////////////////////////////////////////////////
9 ////////////////////////////////////////////////////////////////////////////
10 (
11 const Compiler_Options &options,
12 const std::pair<Table_Id, std::string> &table
13 ):
14 Generator("tables", (table.second + "_introspection.h").c_str(), options),
15 table(table)
16 {
17 }
18
19 ////////////////////////////////////////////////////////////////////////////
21 ////////////////////////////////////////////////////////////////////////////
22 {
23 const Table_Id tid = table.first;
24 const auto &db = options.db;
25
26 out << "#ifndef JOEDB_INTROSPECTION\n";
27
28 if (db.get_freedom(tid).size() > 0)
29 out << "#define JOEDB_INTROSPECTION(field_type, field_name, initial)\n";
30 else
31 out << "#define JOEDB_INTROSPECTION(field_type, field_name)\n";
32
33 out << "#endif\n\n";
34
35 for (const auto &[fid, fname]: db.get_fields(table.first))
36 {
37 out << "JOEDB_INTROSPECTION(";
38
39 const joedb::Type &type = db.get_field_type(tid, fid);
40
41 if (type.get_type_id() == joedb::Type::Type_Id::boolean)
42 out << "bool";
43 else
44 {
45 if (type.get_type_id() == joedb::Type::Type_Id::reference)
46 {
48 out << "::";
49 }
50 write_type(type, false, false);
51 }
52
53 out << ", " << fname;
54
55 if (db.get_freedom(tid).size() > 0)
56 {
57 out << ", ";
58 const Record_Id record_id{db.get_freedom(tid).get_first_used() - 1};
59 write_value(out, db, tid, record_id, fid);
60 }
61 out << ");\n";
62 }
63
64 out << "\n#undef JOEDB_INTROSPECTION\n";
65 }
66}
const std::vector< std::string > & get_name_space() const
Type_Id get_type_id() const
Definition Type.h:40
void write_type(Type type, bool return_type, bool setter_type)
Definition Generator.cpp:42
const Compiler_Options & options
Definition Generator.h:14
introspection_h(const Compiler_Options &options, const std::pair< Table_Id, std::string > &table)
void namespace_write(std::ostream &out, const std::vector< std::string > &n, const char *delimiter)
void write_value(std::ostream &out, const Readable &readable, Table_Id table_id, Record_Id record_id, Field_Id field_id)
One code generator for each of the file generated by joedbc.
Definition Client_h.cpp:5