From 5e0c1cff48c8e113522c88674d6bc0e8678fcebf Mon Sep 17 00:00:00 2001 From: rbock Date: Tue, 8 Apr 2014 22:45:19 +0200 Subject: [PATCH] Moved flag-methods to select_flag classes --- include/sqlpp11/select.h | 26 +-------------- include/sqlpp11/vendor/group_by.h | 1 + include/sqlpp11/vendor/having.h | 1 + include/sqlpp11/vendor/order_by.h | 1 + include/sqlpp11/vendor/select_flag_list.h | 39 ++++++++++++++++++++--- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index f102fc0b..e950e84f 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -130,6 +130,7 @@ namespace sqlpp typename Offset > struct select_t: public detail::select_helper_t::_value_type::template expression_operators>, + FlagList::template _methods_t>, Where::template _methods_t>, GroupBy::template _methods_t>, Having::template _methods_t>, @@ -188,23 +189,6 @@ namespace sqlpp ~select_t() = default; // type update functions - template - auto flags(Args... args) - -> _policies_update_t> - { - static_assert(is_noop_t::value, "flags()/dynamic_flags() must not be called twice"); - return { *this, vendor::select_flag_list_t{args...} }; - } - - template - auto dynamic_flags(Args... args) - -> _policies_update_t> - { - static_assert(is_noop_t::value, "flags()/dynamic_flags() must not be called twice"); - static_assert(_is_dynamic::value, "dynamic_flags must not be called in a static statement"); - return { *this, vendor::select_flag_list_t<_database_t, Args...>{args...} }; - } - template auto columns(Args... args) -> _policies_update_t> @@ -238,14 +222,6 @@ namespace sqlpp } // value adding methods - template - void add_flag(Args... args) - { - static_assert(is_select_flag_list_t::value, "cannot call add_flag() before dynamic_flags()"); - static_assert(is_dynamic_t::value, "cannot call add_flag() before dynamic_flags()"); - return _flag_list.add_flag(*this, args...); - } - template void add_column(Args... args) { diff --git a/include/sqlpp11/vendor/group_by.h b/include/sqlpp11/vendor/group_by.h index 8c6bba6f..29b6438d 100644 --- a/include/sqlpp11/vendor/group_by.h +++ b/include/sqlpp11/vendor/group_by.h @@ -71,6 +71,7 @@ namespace sqlpp template void add_group_by(Expression expression) { + static_assert(_is_dynamic::value, "add_group_by must not be called for static group_by"); static_assert(is_expression_t::value, "invalid expression argument in add_group_by()"); #warning: Need to dispatch to actual add method to prevent error messages from being generated return static_cast(this)->_group_by._dynamic_expressions.emplace_back(expression); diff --git a/include/sqlpp11/vendor/having.h b/include/sqlpp11/vendor/having.h index ad29d987..c75b2a49 100644 --- a/include/sqlpp11/vendor/having.h +++ b/include/sqlpp11/vendor/having.h @@ -69,6 +69,7 @@ namespace sqlpp template void add_having(Expression expression) { + static_assert(_is_dynamic::value, "add_having must not be called for static having"); static_assert(is_expression_t::value, "invalid expression argument in add_having()"); #warning: Need to dispatch to actual add method to prevent error messages from being generated return static_cast(this)->_having._dynamic_expressions.emplace_back(expression); diff --git a/include/sqlpp11/vendor/order_by.h b/include/sqlpp11/vendor/order_by.h index a8bf3edb..4aff0f26 100644 --- a/include/sqlpp11/vendor/order_by.h +++ b/include/sqlpp11/vendor/order_by.h @@ -70,6 +70,7 @@ namespace sqlpp template void add_order_by(Expression expression) { + static_assert(_is_dynamic::value, "add_order_by must not be called for static order_by"); static_assert(is_sort_order_t::value, "invalid expression argument in add_order_by()"); #warning: Need to dispatch to actual add method to prevent error messages from being generated return static_cast(this)->_order_by._dynamic_expressions.emplace_back(expression); diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index d1292da2..b42440ba 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -61,12 +61,18 @@ namespace sqlpp select_flag_list_t& operator=(select_flag_list_t&&) = default; ~select_flag_list_t() = default; - template - void add_flag(const Select&, Flag flag) + template + struct _methods_t { - static_assert(is_select_flag_t::value, "flag arguments require to be select flags"); - _dynamic_flags.emplace_back(flag); - } + template + void add_flag(Flag flag) + { + static_assert(_is_dynamic::value, "add_flag must not be called for static select flags"); + static_assert(is_select_flag_t::value, "invalid select flag argument in add_flag()"); +#warning: Need to dispatch to actual add method to prevent error messages from being generated + return static_cast(this)->_flag_list._dynamic_flags.emplace_back(flag); + } + }; const select_flag_list_t& _flag_list() const { return *this; } _parameter_tuple_t _flags; @@ -76,6 +82,29 @@ namespace sqlpp struct no_select_flag_list_t { using _is_noop = std::true_type; + + template + struct _methods_t + { + using _database_t = typename Policies::_database_t; + template + using _new_select_t = typename Policies::template _policies_update_t; + + template + auto flags(Args... args) + -> _new_select_t> + { + return { *static_cast(this), select_flag_list_t{args...} }; + } + + template + auto dynamic_flags(Args... args) + -> _new_select_t> + { + static_assert(not std::is_same<_database_t, void>::value, "dynamic_flags must not be called in a static statement"); + return { *static_cast(this), vendor::select_flag_list_t<_database_t, Args...>{args...} }; + } + }; };