From f21860e5c57e36e29264cb6588a97c598700c0c0 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 12 Jan 2014 16:26:47 +0100 Subject: [PATCH] Cleaned up a hack in like() --- include/sqlpp11/like.h | 106 ++++++++++++++++++++--------------------- include/sqlpp11/text.h | 2 +- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index e3b74e13..6e5b4c75 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -27,69 +27,67 @@ #ifndef SQLPP_LIKE_H #define SQLPP_LIKE_H -#include +#include #include #include namespace sqlpp { - // The ValueType should be boolean, this is a hack because boolean is not fully defined when the compiler first gets here... - template - struct like_t: public ValueType::_base_value_type::template operators> + template + struct like_t: public boolean::template operators> + { + static_assert(is_text_t::value, "Operand for like() has to be a text"); + static_assert(is_text_t::value, "Pattern for like() has to be a text"); + + struct _value_type: public boolean { - static_assert(is_text_t::value, "Operand for like() has to be a text"); - static_assert(is_text_t::value, "Pattern for like() has to be a text"); - using _parameter_tuple_t = std::tuple; - - struct _value_type: public ValueType::_base_value_type // we require fully defined boolean here - { - using _is_named_expression = std::true_type; - }; - - struct _name_t - { - static constexpr const char* _get_name() { return "LIKE"; } - template - struct _member_t - { - T like; - }; - }; - - like_t(Operand&& operand, Pattern&& pattern): - _operand(std::move(operand)), - _pattern(std::move(pattern)) - {} - - like_t(const Operand& operand, const Pattern& pattern): - _operand(operand), - _pattern(pattern) - {} - - like_t(const like_t&) = default; - like_t(like_t&&) = default; - like_t& operator=(const like_t&) = default; - like_t& operator=(like_t&&) = default; - ~like_t() = default; - - template - void serialize(std::ostream& os, Db& db) const - { - static_assert(Db::_supports_like, "like() not supported by current database"); - _operand.serialize(os, db); - os << " LIKE("; - _pattern.serialize(os, db); - os << ")"; - } - - Operand _operand; - Pattern _pattern; + using _is_named_expression = std::true_type; }; - template - struct interpreter_t> + struct _name_t { - using T = like_t; + static constexpr const char* _get_name() { return "LIKE"; } + template + struct _member_t + { + T like; + }; + }; + + like_t(Operand&& operand, Pattern&& pattern): + _operand(std::move(operand)), + _pattern(std::move(pattern)) + {} + + like_t(const Operand& operand, const Pattern& pattern): + _operand(operand), + _pattern(pattern) + {} + + like_t(const like_t&) = default; + like_t(like_t&&) = default; + like_t& operator=(const like_t&) = default; + like_t& operator=(like_t&&) = default; + ~like_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + static_assert(Db::_supports_like, "like() not supported by current database"); + _operand.serialize(os, db); + os << " LIKE("; + _pattern.serialize(os, db); + os << ")"; + } + + Operand _operand; + Pattern _pattern; + }; + + template + struct interpreter_t> + { + using T = like_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 2902bfa6..af2677b1 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -203,7 +203,7 @@ namespace sqlpp } template - like_t::type> like(T&& t) const + like_t::type> like(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); return { *static_cast(this), {std::forward(t)} };