Joedb 9.1.4
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_unique_index() const
67 {
68 for (const auto &index: indices)
69 if (index.unique)
70 return true;
71 return false;
72 }
73
74 bool has_single_row() const
75 {
76 for (const auto &options: table_options)
77 if (options.second.single_row)
78 return true;
79 return false;
80 }
81
82 void set_name_space(std::vector<std::string> v)
83 {
84 name_space = std::move(v);
85 }
86
87 void set_single_row(Table_Id table_id, bool value)
88 {
89 table_options[table_id].single_row = value;
90 }
91
92 void add_index(Index index)
93 {
94 indices.emplace_back(std::move(index));
95 }
96
97 const Database &get_db() const {return db;}
98 const std::vector<std::string> &get_custom_names() const
99 {
100 return custom_names;
101 }
102 const std::vector<std::string> &get_name_space() const
103 {
104 return name_space;
105 }
106 const std::vector<Index> &get_indices() const {return indices;}
108 {
109 return table_options.find(table_id)->second;
110 }
111 };
112}
113
114#endif
std::map< Table_Id, Table_Options > table_options
std::vector< std::string > custom_names
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
Definition Blob.h:7
bool is_trigger(const Table_Id tid, const Field_Id fid) const
std::vector< Field_Id > field_ids