Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedbc.cpp
Go to the documentation of this file.
2#include "joedb/Multiplexer.h"
8#include "joedb/get_version.h"
9
17
26
30
33
34#include <iostream>
35
36namespace joedb
37{
38 ////////////////////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////////////////////
41 {
42 private:
43 std::vector<std::string> &names;
44
45 public:
46 explicit Custom_Collector(std::vector<std::string> &names): names(names)
47 {
48 }
49
50 void custom(const std::string &name) final
51 {
52 if (!is_identifier(name))
53 throw Exception("custom: invalid identifier");
54 names.emplace_back(name);
55 }
56 };
57
58 ////////////////////////////////////////////////////////////////////////////
59 static int joedbc_main(int argc, char **argv)
60 ////////////////////////////////////////////////////////////////////////////
61 {
62 //
63 // Open existing file from the command line
64 //
65 if (argc <= 2)
66 {
67 std::cerr << "joedb compiler, version " << joedb::get_version() << '\n';
68 std::cerr << "Usage: " << argv[0] << " <file.joedbi> <file.joedbc>\n";
69 return 1;
70 }
71
72 const char * const exe_path = argv[0];
73 const char * const joedbi_file_name = argv[1];
74 const char * const joedbc_file_name = argv[2];
75
76 Compiler_Options options;
77 options.exe_path = std::string(exe_path);
78
79 //
80 // Read file.joedbi
81 //
82 {
83 std::ifstream joedbi_file(joedbi_file_name);
84 if (!joedbi_file)
85 {
86 std::cerr << "Error: could not open " << joedbi_file_name << '\n';
87 return 1;
88 }
89
90 Writable_Journal journal(options.schema_file);
91 Selective_Writable schema_writable(journal, Selective_Writable::schema);
92 Custom_Collector custom_collector(options.custom_names);
93
94 Multiplexer multiplexer{options.db, schema_writable, custom_collector};
95 Interpreter interpreter(options.db, multiplexer, nullptr, multiplexer, 0);
96 interpreter.set_echo(false);
97 interpreter.set_rethrow(true);
98 interpreter.main_loop(joedbi_file, std::cerr);
99 multiplexer.default_checkpoint();
100 }
101
102 for (const auto &[tid, tname]: options.db.get_tables())
103 options.table_options[tid];
104
105 //
106 // Read file.joedbc
107 //
108 std::ifstream joedbc_file(joedbc_file_name);
109 if (!joedbc_file)
110 {
111 std::cerr << "Error: could not open " << joedbc_file_name << '\n';
112 return 1;
113 }
114
115
116 try
117 {
118 parse_compiler_options(joedbc_file, options);
119 }
120 catch(...)
121 {
122 std::cerr << "Error parsing .joedbc file: " << argv[2] << '\n';
123 throw;
124 }
125
126 //
127 // Generate code
128 //
129 generator::Database_h(options).generate();
130 generator::Database_cpp(options).generate();
131 generator::Readonly_Database_h(options).generate();
132 generator::Types_h(options).generate();
133 generator::Readable_h(options).generate();
134
135 generator::readonly_h(options).generate();
136 generator::readonly_cpp(options).generate();
137
138 generator::Writable_Database_h(options).generate();
139 generator::Writable_Database_cpp(options).generate();
140 generator::File_Database_h(options).generate();
141 generator::Readonly_Interpreted_File_Database_h(options).generate();
142 generator::Interpreted_File_Database_h(options).generate();
143 generator::Multiplexer_h(options).generate();
144
145 generator::writable_h(options).generate();
146 generator::writable_cpp(options).generate();
147
148 generator::Client_h(options).generate();
149 generator::File_Client_h(options).generate();
150 generator::Readonly_Client_h(options).generate();
151
152 generator::ids_h(options).generate();
153
154 for (const auto &table: options.db.get_tables())
155 generator::introspection_h(options, table).generate();
156
157 return 0;
158 }
159}
160
161/////////////////////////////////////////////////////////////////////////////
162int main(int argc, char **argv)
163/////////////////////////////////////////////////////////////////////////////
164{
165 return joedb::main_exception_catcher(joedb::joedbc_main, argc, argv);
166}
Custom_Collector(std::vector< std::string > &names)
Definition joedbc.cpp:46
void custom(const std::string &name) final
Definition joedbc.cpp:50
int main()
void parse_compiler_options(std::istream &in, Compiler_Options &compiler_options)
int main_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception from main.
Definition Blob.h:7
bool is_identifier(const std::string &s)
constexpr const char * get_version()
Definition get_version.h:6