#pragma once /* * Copyright (c) 2013-2015, 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. */ #include #include #include #include namespace sqlpp { // USING DATA template struct using_data_t { using_data_t(Tables... tables) : _tables(tables...) { } using_data_t(const using_data_t&) = default; using_data_t(using_data_t&&) = default; using_data_t& operator=(const using_data_t&) = default; using_data_t& operator=(using_data_t&&) = default; ~using_data_t() = default; std::tuple _tables; }; // USING template struct using_t { using _traits = make_traits; using _nodes = detail::type_vector; using _data_t = using_data_t; // Base template to be inherited by the statement template struct _base_t { _base_t(_data_t data) : _data{std::move(data)} { } _data_t _data; // FIXME: Maybe check for unused tables, similar to from using _consistency_check = consistent_t; }; }; SQLPP_PORTABLE_STATIC_ASSERT(assert_using_args_are_tables_t, "arguments for using() must be tables"); template struct check_using { using type = static_combined_check_t< static_check_t::value...>::value, assert_using_args_are_tables_t>>; }; template using check_using_t = typename check_using::type; // NO USING YET struct no_using_t { using _traits = make_traits; using _nodes = detail::type_vector<>; using _data_t = no_data_t; // Base template to be inherited by the statement template struct _base_t { _base_t() = default; _base_t(_data_t data) : _data{std::move(data)} { } _data_t _data; template using _new_statement_t = new_statement_t; using _consistency_check = consistent_t; template auto using_(Tables... tables) const -> _new_statement_t, using_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in using()"); static_assert(sizeof...(Tables), "at least one table required in using()"); return {_using_impl(check_using_t{}, tables...)}; } private: template auto _using_impl(Check, Tables... tables) const -> inconsistent; template auto _using_impl(consistent_t /*unused*/, Tables... tables) const -> _new_statement_t> { static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in using()"); return {static_cast&>(*this), using_data_t{tables...}}; } }; }; // Interpreters template Context& serialize(const using_data_t& t, Context& context) { context << " USING "; interpret_tuple(t._tables, ',', context); return context; } } // namespace sqlpp