Joedb 10.0.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;
54 std::vector<std::string> custom_names;
55
56 std::vector<std::string> name_space;
57 std::vector<Index> indices;
58 std::map<Table_Id, Table_Options> table_options;
59
60 public:
61 bool has_index() const
62 {
63 return indices.size() > 0;
64 }
65
66 bool has_blob() const
67 {
68 for (auto &[table_id, table_name]: db.get_tables())
69 for (auto &[field_id, field_name]: db.get_fields(table_id))
70 if (db.get_field_type(table_id, field_id).get_type_id() == Type::Type_Id::blob)
71 return true;
72 return false;
73 }
74
75 bool has_unique_index() const
76 {
77 for (const auto &index: indices)
78 if (index.unique)
79 return true;
80 return false;
81 }
82
83 bool has_single_row() const
84 {
85 for (const auto &options: table_options)
86 if (options.second.single_row)
87 return true;
88 return false;
89 }
90
91 void set_name_space(std::vector<std::string> v)
92 {
93 name_space = std::move(v);
94 }
95
96 void set_single_row(Table_Id table_id, bool value)
97 {
98 table_options[table_id].single_row = value;
99 }
100
101 void add_index(Index index)
102 {
103 indices.emplace_back(std::move(index));
104 }
105
106 const Database &get_db() const {return db;}
107 const std::vector<std::string> &get_custom_names() const
108 {
109 return custom_names;
110 }
111 const std::vector<std::string> &get_name_space() const
112 {
113 return name_space;
114 }
115 const std::string &get_name_space_back() const
116 {
117 if (name_space.empty())
118 throw Exception("missing name space");
119 else
120 return name_space.back();
121 }
122 const std::vector<Index> &get_indices() const {return indices;}
124 {
125 return table_options.find(table_id)->second;
126 }
127 };
128}
129
130#endif
std::map< Table_Id, Table_Options > table_options
std::vector< std::string > custom_names
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)
const std::vector< Index > & get_indices() const
const Table_Options & get_table_options(Table_Id table_id) const
const Database & get_db() 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
Definition Blob.h:7
bool is_trigger(const Table_Id tid, const Field_Id fid) const
std::vector< Field_Id > field_ids