small refactorings

This commit is contained in:
2021-08-15 13:24:16 +02:00
parent b37b0b55ff
commit b03462da6a
8 changed files with 55 additions and 89 deletions

View File

@@ -51,7 +51,7 @@ namespace usql {
struct Node {
NodeType node_type;
Node(const NodeType type) : node_type(type) {}
explicit Node(const NodeType type) : node_type(type) {}
};
@@ -60,7 +60,7 @@ namespace usql {
int col_index;
bool ascending;
ColOrderNode(const std::string name, bool asc) : Node(NodeType::column_order), col_name(name), col_index(-1), ascending(asc) {}
ColOrderNode(const std::string& name, bool asc) : Node(NodeType::column_order), col_name(name), col_index(-1), ascending(asc) {}
ColOrderNode(int index, bool asc) : Node(NodeType::database_value), col_name(""), col_index(index), ascending(asc) {}
};
@@ -78,7 +78,7 @@ namespace usql {
std::unique_ptr<Node> value;
std::string name;
SelectColNode(std::unique_ptr<Node> column, std::string alias) :
SelectColNode(std::unique_ptr<Node> column, const std::string &alias) :
Node(NodeType::database_value), value(std::move(column)), name(alias) {}
};
@@ -89,7 +89,7 @@ namespace usql {
int length;
bool null;
ColDefNode(const std::string col_name, ColumnType col_type, int col_order, int col_len, bool nullable) :
ColDefNode(const std::string& col_name, ColumnType col_type, int col_order, int col_len, bool nullable) :
Node(NodeType::column_def), name(col_name), type(col_type), order(col_order), length(col_len),
null(nullable) {}
};
@@ -98,7 +98,7 @@ namespace usql {
std::string function; // TODO use enum
std::vector<std::unique_ptr<Node>> params;
FunctionNode(const std::string func_name, std::vector<std::unique_ptr<Node>> pars) :
FunctionNode(const std::string& func_name, std::vector<std::unique_ptr<Node>> pars) :
Node(NodeType::function), function(func_name), params(std::move(pars)) {}
};
@@ -107,7 +107,7 @@ namespace usql {
};
struct ValueNode : Node {
ValueNode(NodeType type) : Node(type) {}
explicit ValueNode(NodeType type) : Node(type) {}
virtual bool isNull() { return false; }
virtual long getIntegerValue() = 0;
@@ -135,7 +135,7 @@ namespace usql {
struct IntValueNode : ValueNode {
long value;
IntValueNode(long value) : ValueNode(NodeType::int_value), value(value) {}
explicit IntValueNode(long value) : ValueNode(NodeType::int_value), value(value) {}
long getIntegerValue() override { return value; };
double getDoubleValue() override { return (double) value; };
@@ -147,7 +147,7 @@ namespace usql {
struct DoubleValueNode : ValueNode {
double value;
DoubleValueNode(double value) : ValueNode(NodeType::float_value), value(value) {}
explicit DoubleValueNode(double value) : ValueNode(NodeType::float_value), value(value) {}
long getIntegerValue() override { return (long) value; };
double getDoubleValue() override { return value; };
@@ -159,7 +159,7 @@ namespace usql {
struct StringValueNode : ValueNode {
std::string value;
StringValueNode(std::string value) : ValueNode(NodeType::string_value), value(value) {}
explicit StringValueNode(const std::string &value) : ValueNode(NodeType::string_value), value(value) {}
long getIntegerValue() override { return std::stoi(value); };
double getDoubleValue() override { return std::stod(value); };
@@ -171,7 +171,7 @@ namespace usql {
struct BooleanValueNode : ValueNode {
bool value;
BooleanValueNode(bool value) : ValueNode(NodeType::bool_value), value(value) {}
explicit BooleanValueNode(bool value) : ValueNode(NodeType::bool_value), value(value) {}
long getIntegerValue() override { return (long) value; };
double getDoubleValue() override { return (double) value; };
@@ -184,7 +184,7 @@ namespace usql {
struct DatabaseValueNode : Node {
std::string col_name;
DatabaseValueNode(std::string name) : Node(NodeType::database_value), col_name(name) {}
explicit DatabaseValueNode(const std::string &name) : Node(NodeType::database_value), col_name(name) {}
};
enum class LogicalOperatorType {
@@ -245,7 +245,7 @@ namespace usql {
std::vector<ColDefNode> cols_defs;
CreateTableNode(const std::string& name, std::vector<ColDefNode> defs) :
Node(NodeType::create_table), table_name(name), cols_defs(defs) {}
Node(NodeType::create_table), table_name(name), cols_defs(std::move(defs)) {}
};
struct InsertIntoTableNode : Node {
@@ -253,8 +253,8 @@ namespace usql {
std::vector<DatabaseValueNode> cols_names;
std::vector<std::unique_ptr<Node>> cols_values;
InsertIntoTableNode(const std::string name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> values) :
Node(NodeType::insert_into), table_name(name), cols_names(names), cols_values(std::move(values)) {}
InsertIntoTableNode(const std::string& name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> values) :
Node(NodeType::insert_into), table_name(name), cols_names(std::move(names)), cols_values(std::move(values)) {}
};
struct SelectFromTableNode : Node {
@@ -266,14 +266,14 @@ namespace usql {
bool distinct;
SelectFromTableNode(std::string name, std::unique_ptr<std::vector<SelectColNode>> names, std::unique_ptr<Node> where_clause, std::vector<ColOrderNode> orderby, OffsetLimitNode offlim, bool distinct_):
Node(NodeType::select_from), table_name(name), cols_names(std::move(names)), where(std::move(where_clause)), order_by(orderby), offset_limit(offlim), distinct(distinct_) {}
Node(NodeType::select_from), table_name(std::move(name)), cols_names(std::move(names)), where(std::move(where_clause)), order_by(std::move(orderby)), offset_limit(offlim), distinct(distinct_) {}
};
struct CreateTableAsSelectNode : Node {
std::string table_name;
std::unique_ptr<Node> select_table;
CreateTableAsSelectNode(const std::string name, std::unique_ptr<Node> table) :
CreateTableAsSelectNode(const std::string& name, std::unique_ptr<Node> table) :
Node(NodeType::create_table_as_select), table_name(name), select_table(std::move(table)) {}
};
@@ -283,7 +283,7 @@ namespace usql {
std::vector<std::unique_ptr<Node>> values;
std::unique_ptr<Node> where;
UpdateTableNode(std::string name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> vals,
UpdateTableNode(const std::string &name, std::vector<DatabaseValueNode> names, std::vector<std::unique_ptr<Node>> vals,
std::unique_ptr<Node> where_clause) :
Node(NodeType::update_table), table_name(name), cols_names(names), values(std::move(vals)),
where(std::move(where_clause)) {}
@@ -293,7 +293,7 @@ namespace usql {
std::string table_name;
std::string filename;
LoadIntoTableNode(const std::string name, std::string file) :
LoadIntoTableNode(const std::string& name, const std::string &file) :
Node(NodeType::load_table), table_name(name), filename(file) {}
};
@@ -301,14 +301,14 @@ namespace usql {
std::string table_name;
std::string filename;
SaveTableNode(const std::string& name, std::string file) :
SaveTableNode(const std::string& name, const std::string &file) :
Node(NodeType::save_table), table_name(name), filename(file) {}
};
struct DropTableNode : Node {
std::string table_name;
DropTableNode(const std::string& name) : Node(NodeType::drop_table), table_name(name) {}
explicit DropTableNode(const std::string& name) : Node(NodeType::drop_table), table_name(name) {}
};
struct DeleteFromTableNode : Node {
@@ -330,7 +330,7 @@ namespace usql {
struct ShowNode : Node {
std::string name;
ShowNode(const std::string& name_) : Node(NodeType::show), name(name_) {}
explicit ShowNode(const std::string& name_) : Node(NodeType::show), name(name_) {}
};