/* * Copyright (c) 2013-2014, Roland Bock * 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_WRAP_OPERAND_H #define SQLPP_DETAIL_WRAP_OPERAND_H #include #include #include #include #include namespace sqlpp { struct boolean; struct integral; struct floating_point; struct text; struct boolean_operand: public alias_operators { using _traits = make_traits<::sqlpp::boolean, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = bool; boolean_operand(): _t{} {} boolean_operand(_value_t t): _t(t) {} boolean_operand(const boolean_operand&) = default; boolean_operand(boolean_operand&&) = default; boolean_operand& operator=(const boolean_operand&) = default; boolean_operand& operator=(boolean_operand&&) = default; ~boolean_operand() = default; bool _is_trivial() const { return _t == false; } _value_t _t; }; template struct serializer_t { using Operand = boolean_operand; static Context& _(const Operand& t, Context& context) { context << t._t; return context; } }; struct integral_operand: public alias_operators { using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = int64_t; integral_operand(): _t{} {} integral_operand(_value_t t): _t(t) {} integral_operand(const integral_operand&) = default; integral_operand(integral_operand&&) = default; integral_operand& operator=(const integral_operand&) = default; integral_operand& operator=(integral_operand&&) = default; ~integral_operand() = default; bool _is_trivial() const { return _t == 0; } _value_t _t; }; template struct serializer_t { using Operand = integral_operand; static Context& _(const Operand& t, Context& context) { context << t._t; return context; } }; struct floating_point_operand: public alias_operators { using _traits = make_traits<::sqlpp::floating_point, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = double; floating_point_operand(): _t{} {} floating_point_operand(_value_t t): _t(t) {} floating_point_operand(const floating_point_operand&) = default; floating_point_operand(floating_point_operand&&) = default; floating_point_operand& operator=(const floating_point_operand&) = default; floating_point_operand& operator=(floating_point_operand&&) = default; ~floating_point_operand() = default; bool _is_trivial() const { return _t == 0; } _value_t _t; }; template struct serializer_t { using Operand = floating_point_operand; static Context& _(const Operand& t, Context& context) { context << t._t; return context; } }; struct text_operand: public alias_operators { using _traits = make_traits<::sqlpp::text, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; using _value_t = std::string; text_operand(): _t{} {} text_operand(_value_t t): _t(t) {} text_operand(const text_operand&) = default; text_operand(text_operand&&) = default; text_operand& operator=(const text_operand&) = default; text_operand& operator=(text_operand&&) = default; ~text_operand() = default; bool _is_trivial() const { return _t.empty(); } _value_t _t; }; template struct serializer_t { using Operand = text_operand; static Context& _(const Operand& t, Context& context) { context << '\'' << context.escape(t._t) << '\''; return context; } }; template struct wrap_operand { using type = T; }; template<> struct wrap_operand { using type = boolean_operand; }; template struct wrap_operand::value>::type> { using type = integral_operand; }; template struct wrap_operand::value>::type> { using type = floating_point_operand; }; template struct wrap_operand::value and not is_result_field_t::value>::type> { using type = text_operand; }; } #endif