|
- #pragma once
-
- #include "tables.h"
-
- namespace cpphibernate {
- namespace schema {
-
- namespace __impl
- {
-
- /* tables_t */
-
- template<typename... T_tables>
- using tables_t = hana::tuple<T_tables...>;
-
- /* tables_builder */
-
- template<typename T, typename>
- struct tables_builder
- {
- template<typename... T_args>
- static constexpr decltype(auto) apply(T_args&&...)
- { static_assert(sizeof...(T_args) == -1, "Invalid parameters for make_tables(...)!"); }
- };
-
- template<typename... T>
- struct tables_builder<
- mp::list<T...>,
- mp::enable_if_t<mp::is_true_v<
- is_table_v<mp::decay_t<T>>...>>>
- {
- template<typename... T_args>
- static constexpr decltype(auto) apply(T_args&&... args)
- {
- using tables_type = tables_t<T_args...>;
- return tables_type(std::forward<T_args>(args)...);
- }
- };
-
- /* find_table_builder */
-
- template<typename X, typename>
- struct find_table_builder
- {
- template<typename... T_args>
- static constexpr decltype(auto) apply(T_args&&... args)
- { static_assert(sizeof...(T_args) == -1, "Invalid parameters for find_table(...)!"); }
- };
-
- template<typename T_tables, typename T_dataset>
- struct find_table_builder<
- mp::list<T_tables, T_dataset>,
- mp::enable_if_t<
- is_tables_v<mp::decay_t<T_tables>>
- && mp::is_same_v<hana::type_tag, hana::tag_of_t<T_dataset>>
- >>
- {
- template<size_t I, size_t N, typename = void>
- struct helper;
-
- template<size_t N>
- struct helper<N, N, void>
- { static_assert(N != N, "Table for given datatype does not exist!"); };
-
- template<size_t I, size_t N>
- struct helper<I, N, mp::enable_if_t<
- decltype(hana::not_equal(std::declval<T_tables>()[hana::size_c<I>].wrapped_dataset, T_dataset { }))::value>>
- {
- static constexpr decltype(auto) apply(T_tables&& tables)
- { return helper<I+1, N>::apply(std::forward<T_tables>(tables)); }
- };
-
- template<size_t I, size_t N>
- struct helper<I, N, mp::enable_if_t<
- decltype(hana::equal(std::declval<T_tables>()[hana::size_c<I>].wrapped_dataset, T_dataset { }))::value>>
- {
- static constexpr decltype(auto) apply(T_tables&& tables)
- { return std::forward<T_tables>(tables)[hana::size_c<I>]; }
- };
-
- static constexpr decltype(auto) apply(T_tables&& tables, T_dataset&&)
- {
- using count_type = mp::decay_t<decltype(hana::size(std::declval<T_tables>()))>;
- return helper<0, count_type::value>::apply(std::forward<T_tables>(tables));
- }
- };
-
- /* is_tables_impl */
-
- template<typename T, typename = void>
- struct is_tables_impl
- : mp::false_t
- { };
-
- template<typename... T>
- struct is_tables_impl<
- tables_t<T...>,
- mp::enable_if_t<mp::is_true_v<is_table_v<mp::decay_t<T>>...>>>
- : mp::true_t
- { };
-
- }
-
- /* is_tables */
-
- template<typename T>
- struct is_tables
- : public __impl::is_tables_impl<T>
- { };
-
- } }
|