2014-03-24 03:54:44 +08:00
|
|
|
/*
|
2014-03-27 23:43:36 +08:00
|
|
|
* Copyright (c) 2013-2014, Roland Bock
|
2014-03-24 03:54:44 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H
|
|
|
|
#define SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
#include <sqlpp11/value_type_fwd.h>
|
2014-03-24 03:54:44 +08:00
|
|
|
#include <sqlpp11/alias.h>
|
|
|
|
#include <sqlpp11/sort_order.h>
|
2014-06-14 00:51:51 +08:00
|
|
|
#include <sqlpp11/expression_fwd.h>
|
|
|
|
#include <sqlpp11/in_fwd.h>
|
|
|
|
#include <sqlpp11/is_null_fwd.h>
|
2014-08-19 03:10:58 +08:00
|
|
|
#include <sqlpp11/wrap_operand_fwd.h>
|
2014-11-29 21:29:54 +08:00
|
|
|
#include <sqlpp11/logic.h>
|
2014-03-24 03:54:44 +08:00
|
|
|
|
|
|
|
namespace sqlpp
|
|
|
|
{
|
|
|
|
// basic operators
|
2014-08-25 14:43:42 +08:00
|
|
|
template<typename Expr, typename ValueType>
|
2014-03-24 03:54:44 +08:00
|
|
|
struct basic_expression_operators
|
|
|
|
{
|
|
|
|
template<typename T>
|
|
|
|
struct _is_valid_comparison_operand
|
2014-06-14 13:45:10 +08:00
|
|
|
{
|
|
|
|
static constexpr bool value =
|
|
|
|
(is_expression_t<T>::value // expressions are OK
|
|
|
|
or is_multi_expression_t<T>::value) // multi-expressions like ANY are OK for comparisons, too
|
2014-08-25 14:43:42 +08:00
|
|
|
and ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course
|
2014-06-14 13:45:10 +08:00
|
|
|
;
|
|
|
|
};
|
2014-03-24 03:54:44 +08:00
|
|
|
|
|
|
|
template<typename T>
|
2014-08-25 14:43:42 +08:00
|
|
|
equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-06-14 13:43:27 +08:00
|
|
|
using rhs = wrap_operand_t<T>;
|
2014-03-24 03:54:44 +08:00
|
|
|
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), {rhs{t}} };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-08-25 14:43:42 +08:00
|
|
|
not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-06-14 13:43:27 +08:00
|
|
|
using rhs = wrap_operand_t<T>;
|
2014-03-24 03:54:44 +08:00
|
|
|
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), {rhs{t}} };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-08-25 14:43:42 +08:00
|
|
|
less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-06-14 13:43:27 +08:00
|
|
|
using rhs = wrap_operand_t<T>;
|
2014-03-24 03:54:44 +08:00
|
|
|
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), rhs{t} };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-08-25 14:43:42 +08:00
|
|
|
less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-06-14 13:43:27 +08:00
|
|
|
using rhs = wrap_operand_t<T>;
|
2014-03-24 03:54:44 +08:00
|
|
|
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), rhs{t} };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-08-25 14:43:42 +08:00
|
|
|
greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-06-14 13:43:27 +08:00
|
|
|
using rhs = wrap_operand_t<T>;
|
2014-03-24 03:54:44 +08:00
|
|
|
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), rhs{t} };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2014-08-25 14:43:42 +08:00
|
|
|
greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-06-14 13:43:27 +08:00
|
|
|
using rhs = wrap_operand_t<T>;
|
2014-03-24 03:54:44 +08:00
|
|
|
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), rhs{t} };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-01 02:40:34 +08:00
|
|
|
is_null_t<Expr> is_null() const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this) };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-01 02:40:34 +08:00
|
|
|
is_not_null_t<Expr> is_not_null() const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this) };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
sort_order_t<Expr, sort_type::asc> asc() const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this) };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
sort_order_t<Expr, sort_type::desc> desc() const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this) };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hint: use value_list wrapper for containers...
|
|
|
|
template<typename... T>
|
2014-12-01 02:40:34 +08:00
|
|
|
in_t<Expr, wrap_operand_t<T>...> in(T... t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-11-29 21:29:54 +08:00
|
|
|
static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... T>
|
2014-12-01 02:40:34 +08:00
|
|
|
not_in_t<Expr, wrap_operand_t<T>...> not_in(T... t) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-11-29 21:29:54 +08:00
|
|
|
static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
2014-06-02 13:48:05 +08:00
|
|
|
};
|
2014-03-24 03:54:44 +08:00
|
|
|
|
2014-08-25 14:43:42 +08:00
|
|
|
template<typename Expr>
|
2014-06-02 13:48:05 +08:00
|
|
|
struct alias_operators
|
|
|
|
{
|
2014-03-24 03:54:44 +08:00
|
|
|
template<typename alias_provider>
|
2014-08-25 14:43:42 +08:00
|
|
|
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
|
2014-03-24 03:54:44 +08:00
|
|
|
{
|
2014-08-25 14:43:42 +08:00
|
|
|
return { *static_cast<const Expr*>(this) };
|
2014-03-24 03:54:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|