From 38c17f093615a16a4b4ec6dc2b5d3edb5c1d3895 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 27 Sep 2018 21:40:52 -0400 Subject: More hkutil refactoring All database access goes through hatkirby::database now. verbly::token, verbly::statement::condition, and verbly::part have been converted to use mpark::variant now. verbly::binding has been deleted, and replaced with a mpark::variant typedef in statement.h. This means that the only remaining tagged union class is verbly::generator::part. refs #5 --- lib/statement.h | 96 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 41 deletions(-) (limited to 'lib/statement.h') diff --git a/lib/statement.h b/lib/statement.h index 2fadf05..6c2e42e 100644 --- a/lib/statement.h +++ b/lib/statement.h @@ -4,8 +4,8 @@ #include #include #include -#include -#include "binding.h" +#include +#include #include "enums.h" #include "field.h" #include "filter.h" @@ -15,14 +15,28 @@ namespace verbly { class filter; class order; + using field_binding = + std::tuple; + + using binding = + mpark::variant< + mpark::monostate, + std::string, + int, + field_binding>; + class statement { public: statement(object context, filter queryFilter); - std::string getQueryString(std::list select, order sortOrder, int limit, bool debug = false) const; + std::string getQueryString( + std::list select, + order sortOrder, + int limit, + bool debug = false) const; - std::list getBindings() const; + std::list getBindings() const; private: @@ -108,23 +122,6 @@ namespace verbly { is_null }; - // Copy and move constructors - - condition(const condition& other); - condition(condition&& other); - - // Assignment - - condition& operator=(condition other); - - // Swap - - friend void swap(condition& first, condition& second); - - // Destructor - - ~condition(); - // Accessors type getType() const @@ -134,13 +131,21 @@ namespace verbly { // Empty - condition(); + condition() = default; // Singleton - condition(std::string table, std::string column, bool isNull); + condition( + std::string table, + std::string column, + bool isNull); - condition(std::string table, std::string column, comparison comp, binding value, object parentObject = object::undefined); + condition( + std::string table, + std::string column, + comparison comp, + binding value, + object parentObject = object::undefined); // Group @@ -156,30 +161,39 @@ namespace verbly { std::string toSql(bool toplevel, bool debug = false) const; - std::list flattenBindings() const; + std::list flattenBindings() const; condition flatten() const; - condition resolveCompareFields(object context, std::string tableName) const; + condition resolveCompareFields( + object context, + std::string tableName) const; private: - union { - struct { - std::string table_; - std::string column_; - comparison comparison_; - binding value_; - object parentObject_; - } singleton_; - struct { - std::list children_; - bool orlogic_; - } group_; + + struct singleton_type { + std::string table; + std::string column; + comparison comparison; + binding value; + object parentObject; }; - type type_; - }; - friend void swap(condition& first, condition& second); + struct group_type { + std::list children; + bool orlogic; + }; + + using variant_type = + mpark::variant< + mpark::monostate, + singleton_type, + group_type>; + + variant_type variant_; + + type type_ = type::empty; + }; class with { public: -- cgit 1.4.1