Joedb 10.4.3
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Compiler_Options.h
Go to the documentation of this file.
1#ifndef joedb_Compiler_Options_declared
2#define joedb_Compiler_Options_declared
3
6
7#include <string>
8#include <vector>
9
10namespace joedb
11{
12 /// @ingroup compiler
14 {
15 public:
16 struct Index
17 {
18 bool unique;
19 bool ordered;
20 std::string name;
22 std::vector<Field_Id> field_ids;
23
24 bool is_trigger(const Table_Id tid, const Field_Id fid) const
25 {
26 if (tid != table_id)
27 return false;
28
29 int index = int(field_ids.size());
30 while (--index >= 0)
31 if (field_ids[index] == fid)
32 break;
33
34 if (index < 0)
35 return false;
36
37 if (unique)
38 for (auto id: field_ids)
39 if (id > fid)
40 return false;
41
42 return true;
43 }
44 };
45
47 {
48 bool single_row = false;
49 };
50
51 public:
52 std::string exe_path;
53 std::string output_path;
54 std::string base_name;
55
58 std::vector<std::string> custom_names;
59
60 std::vector<std::string> name_space;
61 std::vector<Index> indices;
62 std::map<Table_Id, Table_Options> table_options;
63
64 public:
65 bool has_ordered_index() const
66 {
67 for (const auto &index: indices)
68 if (index.ordered)
69 return true;
70 return false;
71 }
72
74 {
75 for (const auto &index: indices)
76 if (!index.ordered)
77 return true;
78 return false;
79 }
80
81 bool has_blob() const
82 {
83 for (const auto &[table_id, table_name]: db.get_tables())
84 for (const auto &[field_id, field_name]: db.get_fields(table_id))
85 if (db.get_field_type(table_id, field_id).get_type_id() == Type::Type_Id::blob)
86 return true;
87 return false;
88 }
89
90 bool has_unique_index() const
91 {
92 for (const auto &index: indices)
93 if (index.unique)
94 return true;
95 return false;
96 }
97
98 bool has_single_row() const
99 {
100 for (const auto &[table_id, options]: table_options)
101 if (options.single_row)
102 return true;
103 return false;
104 }
105
106 bool has_multi_row() const
107 {
108 for (const auto &[table_id, options]: table_options)
109 if (!options.single_row)
110 return true;
111 return false;
112 }
113
114 bool is_unique_field_name(const std::string &field_name) const
115 {
116 int count = 0;
117
118 for (const auto &[table_id, options]: table_options)
119 for (const auto &[field_id, name]: db.get_fields(table_id))
120 if (name == field_name)
121 if (++count > 1)
122 break;
123
124 return count == 1;
125 }
126
127 bool has_table(const std::string &table_name) const
128 {
129 for (const auto &[table_id, name]: db.get_tables())
130 if (name == table_name)
131 return true;
132 return false;
133 }
134
135 void set_name_space(std::vector<std::string> v)
136 {
137 name_space = std::move(v);
138 }
139
140 void set_single_row(Table_Id table_id, bool value)
141 {
142 table_options[table_id].single_row = value;
143 }
144
145 void add_index(Index index)
146 {
147 indices.emplace_back(std::move(index));
148 }
149
150 const Database &get_db() const {return db;}
151 const std::vector<std::string> &get_custom_names() const
152 {
153 return custom_names;
154 }
155 const std::vector<std::string> &get_name_space() const
156 {
157 return name_space;
158 }
159 const std::string &get_name_space_back() const
160 {
161 if (name_space.empty())
162 throw Exception("missing name space");
163 else
164 return name_space.back();
165 }
166 const std::vector<Index> &get_indices() const {return indices;}
168 {
169 return table_options.find(table_id)->second;
170 }
171 std::string get_path(const std::string &schema) const
172 {
173 if (schema == name_space.back())
174 return std::string("..");
175 else
176 return schema;
177 }
178 };
179}
180
181#endif
std::map< Table_Id, Table_Options > table_options
std::vector< std::string > custom_names
std::string get_path(const std::string &schema) const
const std::string & get_name_space_back() const
void add_index(Index index)
std::vector< std::string > name_space
const std::vector< std::string > & get_custom_names() const
std::vector< Index > indices
const std::vector< std::string > & get_name_space() const
void set_single_row(Table_Id table_id, bool value)
void set_name_space(std::vector< std::string > v)
bool is_unique_field_name(const std::string &field_name) const
const std::vector< Index > & get_indices() const
const Table_Options & get_table_options(Table_Id table_id) 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 Type & get_field_type(Table_Id table_id, Field_Id field_id) const override
const std::map< Field_Id, std::string > & get_fields(Table_Id table_id) const override
Type_Id get_type_id() const
Definition Type.h:41
bool is_trigger(const Table_Id tid, const Field_Id fid) const
std::vector< Field_Id > field_ids