/* * Copyright (c) 2013, 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_PARAMETER_LIST_H #define SQLPP_PARAMETER_LIST_H #include #include namespace sqlpp { namespace detail { template struct or_t; template struct or_t { static constexpr bool value = T::value or or_t::value; }; template<> struct or_t<> { static constexpr bool value = false; }; } template struct parameter_list_t { static_assert(detail::wrong::value, "Template parameter for parameter_list_t has to be a tuple"); }; template struct parameter_list_t>: public Parameter::_instance_t... { using _member_tuple_t = std::tuple; using size = std::integral_constant; using _contains_trivial_value_is_null_t = detail::or_t; parameter_list_t(): Parameter::_instance_t({typename Parameter::_trivial_value_is_null_t()})... {} template void _bind(Target& target) const { _bind_impl(target, index_t<0>()); } private: template struct index_t {}; // this is just for overloading template void _bind_impl(Target& target, const index_t&) const { const auto& parameter = static_cast::type&>(*this)(); parameter.bind(target, index); _bind_impl(target, index_t()); } template void _bind_impl(Target& target, const index_t&) const { } }; namespace detail { template struct get_parameter_tuple { using type = std::tuple<>; }; template struct get_parameter_tuple::value, void>::type> { using type = std::tuple; }; template struct get_parameter_tuple, void> { // cat together parameter tuples using type = decltype(std::tuple_cat(std::declval::type>()...)); }; template struct get_parameter_tuple::value, void>::type> { using type = typename get_parameter_tuple::type; }; } template struct make_parameter_list_t { using type = parameter_list_t::type>::type>; }; template size_t set_parameter_index(T& t, size_t index); namespace detail { template struct set_parameter_index_t { size_t operator()(Exp& e, size_t index) { return index; } }; template struct set_parameter_index_t::value, void>::type> { size_t operator()(Exp& e, size_t index) { return e._set_parameter_index(index); } }; template struct set_parameter_index_t, void> { template struct type{}; size_t operator()(std::tuple& t, size_t index) { return impl(t, index, type<0>()); } private: template size_t impl(std::tuple& t, size_t index, const type&) { index = sqlpp::set_parameter_index(std::get(t), index); return impl(t, index, type()); } size_t impl(std::tuple& t, size_t index, const type&) { return index; } }; template struct set_parameter_index_t::value, void>::type> { size_t operator()(Exp& e, size_t index) { return e._set_parameter_index(index); } }; } template size_t set_parameter_index(T& t, size_t index) { return detail::set_parameter_index_t()(t, index); } } #endif