Joedb 10.2.1
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 const Compiler_Options *parent_options
12 ):
13 Generator(".", "ids.h", options),
14 parent_options(parent_options)
15 {
16 }
17
18 ////////////////////////////////////////////////////////////////////////////
20 ////////////////////////////////////////////////////////////////////////////
21 {
22 const Database_Schema &db = options.get_db();
23 auto tables = db.get_tables();
24
26
27 if (parent_options)
28 out << R"RRR(
29#include "../../ids.h"
30
31)RRR";
32 else
33 out << R"RRR(
34#include "joedb/index_types.h"
35
36)RRR";
37
39
40 out << R"RRR(
41 using joedb::Record_Id;
42 using joedb::Table_Id;
43 using joedb::Field_Id;
44)RRR";
45
46 for (const auto &[tid, tname]: tables)
47 {
48 out << '\n';
49 if (parent_options && parent_options->has_table(tname))
50 {
51 out << " using id_of_" << tname << " = ";
52 namespace_write(out, parent_options->name_space);
53 out << "::id_of_" << tname << ";\n";
54 }
55 else
56 {
57 out << " /// Strongly-typed wrapper around an integer representing a row of the " << tname << " table\n";
58 out << " class id_of_" << tname << "\n {\n";
59 out << " private:\n";
60 out << " Record_Id id;\n";
61 out << "\n public:\n";
62 out << " constexpr explicit id_of_" << tname << "(joedb::index_t id): id(Record_Id(id)) {}\n";
63 out << " constexpr explicit id_of_" << tname << "(Record_Id id): id(id) {}\n";
64 out << " constexpr id_of_" << tname << "(): id(joedb::Record_Id::null) {}\n";
65 out << " constexpr bool is_null() const {return id.is_null();}\n";
66 out << " constexpr bool is_not_null() const {return id.is_not_null();}\n";
67 out << " constexpr auto get_id() const {return to_underlying(id);}\n";
68 out << " constexpr Record_Id get_record_id() const {return id;}\n";
69 out << " constexpr bool operator==(id_of_" << tname << " x) const {return id == x.id;}\n";
70 out << " constexpr bool operator!=(id_of_" << tname << " x) const {return id != x.id;}\n";
71 out << " constexpr bool operator<(id_of_" << tname << " x) const {return id < x.id;}\n";
72 out << " constexpr bool operator>(id_of_" << tname << " x) const {return id > x.id;}\n";
73 out << " constexpr bool operator<=(id_of_" << tname << " x) const {return id <= x.id;}\n";
74 out << " constexpr bool operator>=(id_of_" << tname << " x) const {return id >= x.id;}\n";
75 out << " constexpr id_of_" << tname << " operator[](size_t i) const {return id_of_" << tname << "(id + i);}\n";
76 out << " };\n";
77 }
78 }
79
82 }
83}
std::vector< std::string > name_space
const std::vector< std::string > & get_name_space() const
const Database & get_db() const
bool has_table(const std::string &table_name) const
const std::map< Table_Id, std::string > & get_tables() const override
const Compiler_Options & options
Definition Generator.h:13
ids_h(const Compiler_Options &options, const Compiler_Options *parent_options)
Definition ids_h.cpp:9
void generate() override
Definition ids_h.cpp:19
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_write(std::ostream &out, const std::vector< std::string > &n, const char *delimiter)
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.
Definition Client_h.cpp:5