Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
ids_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(".", "ids.h", options)
13 {
14 }
15
16 ////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////
19 {
20 const Database_Schema &db = options.get_db();
21 auto tables = db.get_tables();
22
24
25 out << R"RRR(
26#include "joedb/index_types.h"
27
28)RRR";
29
31
32 out << R"RRR(
33 using joedb::Record_Id;
34 using joedb::Table_Id;
35 using joedb::Field_Id;
36)RRR";
37
38 for (const auto &[tid, tname]: tables)
39 {
40 out << '\n';
41 out << " /// Strongly-typed wrapper around an integer representing a row of the " << tname << " table\n";
42 out << " class id_of_" << tname << "\n {\n";
43 out << " private:\n";
44 out << " Record_Id id;\n";
45 out << "\n public:\n";
46 out << " constexpr explicit id_of_" << tname << "(size_t id): id(Record_Id(id)) {}\n";
47 out << " constexpr explicit id_of_" << tname << "(Record_Id id): id(id) {}\n";
48 out << " constexpr id_of_" << tname << "(): id(Record_Id(0)) {}\n";
49 out << " constexpr bool is_null() const {return id == Record_Id(0);}\n";
50 out << " constexpr bool is_not_null() const {return id != Record_Id(0);}\n";
51 out << " constexpr size_t get_id() const {return size_t(id);}\n";
52 out << " constexpr Record_Id get_record_id() const {return id;}\n";
53 out << " constexpr bool operator==(id_of_" << tname << " x) const {return id == x.id;}\n";
54 out << " constexpr bool operator!=(id_of_" << tname << " x) const {return id != x.id;}\n";
55 out << " constexpr bool operator<(id_of_" << tname << " x) const {return id < x.id;}\n";
56 out << " constexpr bool operator>(id_of_" << tname << " x) const {return id > x.id;}\n";
57 out << " constexpr bool operator<=(id_of_" << tname << " x) const {return id <= x.id;}\n";
58 out << " constexpr bool operator>=(id_of_" << tname << " x) const {return id >= x.id;}\n";
59 out << " constexpr id_of_" << tname << " operator[](size_t i) const {return id_of_" << tname << "(id + i);}\n";
60 out << " };\n";
61 }
62
64 out << "\n#endif\n";
65 }
66}
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
ids_h(const Compiler_Options &options)
Definition ids_h.cpp:9
void generate() override
Definition ids_h.cpp:17
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.
Definition Client_h.cpp:5