Joedb 10.2.1
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 std::string name;
21 std::vector<Field_Id> field_ids;
22
23 bool is_trigger(const Table_Id tid, const Field_Id fid) const
24 {
25 if (tid != table_id)
26 return false;
27
28 int index = int(field_ids.size());
29 while (--index >= 0)
30 if (field_ids[index] == fid)
31 break;
32
33 if (index < 0)
34 return false;
35
36 if (unique)
37 for (auto id: field_ids)
38 if (id > fid)
39 return false;
40
41 return true;
42 }
43 };
44
46 {
47 bool single_row = false;
48 };
49
50 public:
51 std::string exe_path;
52 std::string output_path;
53 std::string base_name;
54
57 std::vector<std::string> custom_names;
58
59 std::vector<std::string> name_space;
60 std::vector<Index> indices;
61 std::map<Table_Id, Table_Options> table_options;
62
63 public:
64 bool has_index() const
65 {
66 return indices.size() > 0;
67 }
68
69 bool has_blob() const
70 {
71 for (const auto &[table_id, table_name]: db.get_tables())
72 for (const auto &[field_id, field_name]: db.get_fields(table_id))
73 if (db.get_field_type(table_id, field_id).get_type_id() == Type::Type_Id::blob)
74 return true;
75 return false;
76 }
77
78 bool has_unique_index() const
79 {
80 for (const auto &index: indices)
81 if (index.unique)
82 return true;
83 return false;
84 }
85
86 bool has_single_row() const
87 {
88 for (const auto &[table_id, options]: table_options)
89 if (options.single_row)
90 return true;
91 return false;
92 }
93
94 bool has_multi_row() const
95 {
96 for (const auto &[table_id, options]: table_options)
97 if (!options.single_row)
98 return true;
99 return false;
100 }
101
102 bool is_unique_field_name(const std::string &field_name) const
103 {
104 int count = 0;
105
106 for (const auto &[table_id, options]: table_options)
107 for (const auto &[field_id, name]: db.get_fields(table_id))
108 if (name == field_name)
109 if (++count > 1)
110 break;
111
112 return count == 1;
113 }
114
115 bool has_table(const std::string &table_name) const
116 {
117 for (const auto &[table_id, name]: db.get_tables())
118 if (name == table_name)
119 return true;
120 return false;
121 }
122
123 void set_name_space(std::vector<std::string> v)
124 {
125 name_space = std::move(v);
126 }
127
128 void set_single_row(Table_Id table_id, bool value)
129 {
130 table_options[table_id].single_row = value;
131 }
132
133 void add_index(Index index)
134 {
135 indices.emplace_back(std::move(index));
136 }
137
138 const Database &get_db() const {return db;}
139 const std::vector<std::string> &get_custom_names() const
140 {
141 return custom_names;
142 }
143 const std::vector<std::string> &get_name_space() const
144 {
145 return name_space;
146 }
147 const std::string &get_name_space_back() const
148 {
149 if (name_space.empty())
150 throw Exception("missing name space");
151 else
152 return name_space.back();
153 }
154 const std::vector<Index> &get_indices() const {return indices;}
156 {
157 return table_options.find(table_id)->second;
158 }
159 std::string get_path(const std::string &schema) const
160 {
161 if (schema == name_space.back())
162 return std::string("..");
163 else
164 return schema;
165 }
166 };
167}
168
169#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