Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Types_h.cpp
Go to the documentation of this file.
3
4namespace joedb::generator
5{
6 ////////////////////////////////////////////////////////////////////////////
8 ////////////////////////////////////////////////////////////////////////////
9 (
10 const Compiler_Options &options
11 ):
12 Generator(".", "Types.h", options)
13 {
14 }
15
16 ////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////
19 {
20 const Database &db = options.get_db();
21 auto tables = db.get_tables();
22
24
25 out << R"RRR(
26#include "Database.h"
27
28)RRR";
29
31
32 static constexpr const char * const type_names[] =
33 {
34 "Writable_Database",
35 "Client",
36 "Database",
37 "File_Client",
38 "File_Database",
39 "Interpreted_File_Database",
40 "Readable",
41 "Readonly_Client",
42 "Readonly_Database",
43 "Readonly_Interpreted_File_Database",
44 };
45
46 out << '\n';
47 for (const char * const type_name: type_names)
48 out << " class " << type_name << ";\n";
49
50 out << R"RRR(
51 /// All types defined for this database, listed in a class (for use as template parameter)
52 class Types
53 {
54 public:
55)RRR";
56
57 const std::string ns = namespace_string(options.get_name_space()) + "::";
58
59 for (const char * const type_name: type_names)
60 out << " using " << type_name << " = " << ns << type_name << ";\n";
61
62 for (const auto &[tid, tname]: tables)
63 {
64 out << '\n';
65 out << " using " << "id_of_" << tname;
66 out << " = " << ns << "id_of_" << tname << ";\n";
67 out << " using iterator_of_" << tname;
68 out << " = " << ns << "container_of_" << tname << "::iterator;\n";
69 }
70
71 out << " };\n";
72
74 out << "\n#endif\n";
75 }
76}
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 Compiler_Options & options
Definition Generator.h:14
void generate() override
Definition Types_h.cpp:17
Types_h(const Compiler_Options &options)
Definition Types_h.cpp:9
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)
std::string namespace_string(const std::vector< std::string > &n, const char *delimiter)
One code generator for each of the file generated by joedbc.
Definition Client_h.cpp:5