You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

112 lines
3.4 KiB

  1. #pragma once
  2. #include "tables.h"
  3. namespace cpphibernate {
  4. namespace schema {
  5. namespace __impl
  6. {
  7. /* tables_t */
  8. template<typename... T_tables>
  9. using tables_t = hana::tuple<T_tables...>;
  10. /* tables_builder */
  11. template<typename T, typename>
  12. struct tables_builder
  13. {
  14. template<typename... T_args>
  15. static constexpr decltype(auto) apply(T_args&&...)
  16. { static_assert(sizeof...(T_args) == -1, "Invalid parameters for make_tables(...)!"); }
  17. };
  18. template<typename... T>
  19. struct tables_builder<
  20. mp::list<T...>,
  21. mp::enable_if_t<mp::is_true_v<
  22. is_table_v<mp::decay_t<T>>...>>>
  23. {
  24. template<typename... T_args>
  25. static constexpr decltype(auto) apply(T_args&&... args)
  26. {
  27. using tables_type = tables_t<T_args...>;
  28. return tables_type(std::forward<T_args>(args)...);
  29. }
  30. };
  31. /* find_table_builder */
  32. template<typename X, typename>
  33. struct find_table_builder
  34. {
  35. template<typename... T_args>
  36. static constexpr decltype(auto) apply(T_args&&... args)
  37. { static_assert(sizeof...(T_args) == -1, "Invalid parameters for find_table(...)!"); }
  38. };
  39. template<typename T_tables, typename T_dataset>
  40. struct find_table_builder<
  41. mp::list<T_tables, T_dataset>,
  42. mp::enable_if_t<
  43. is_tables_v<mp::decay_t<T_tables>>
  44. && mp::is_same_v<hana::type_tag, hana::tag_of_t<T_dataset>>
  45. >>
  46. {
  47. template<size_t I, size_t N, typename = void>
  48. struct helper;
  49. template<size_t N>
  50. struct helper<N, N, void>
  51. { static_assert(N != N, "Table for given datatype does not exist!"); };
  52. template<size_t I, size_t N>
  53. struct helper<I, N, mp::enable_if_t<
  54. decltype(hana::not_equal(std::declval<T_tables>()[hana::size_c<I>].wrapped_dataset, T_dataset { }))::value>>
  55. {
  56. static constexpr decltype(auto) apply(T_tables&& tables)
  57. { return helper<I+1, N>::apply(std::forward<T_tables>(tables)); }
  58. };
  59. template<size_t I, size_t N>
  60. struct helper<I, N, mp::enable_if_t<
  61. decltype(hana::equal(std::declval<T_tables>()[hana::size_c<I>].wrapped_dataset, T_dataset { }))::value>>
  62. {
  63. static constexpr decltype(auto) apply(T_tables&& tables)
  64. { return std::forward<T_tables>(tables)[hana::size_c<I>]; }
  65. };
  66. static constexpr decltype(auto) apply(T_tables&& tables, T_dataset&&)
  67. {
  68. using count_type = mp::decay_t<decltype(hana::size(std::declval<T_tables>()))>;
  69. return helper<0, count_type::value>::apply(std::forward<T_tables>(tables));
  70. }
  71. };
  72. /* is_tables_impl */
  73. template<typename T, typename = void>
  74. struct is_tables_impl
  75. : mp::false_t
  76. { };
  77. template<typename... T>
  78. struct is_tables_impl<
  79. tables_t<T...>,
  80. mp::enable_if_t<mp::is_true_v<is_table_v<mp::decay_t<T>>...>>>
  81. : mp::true_t
  82. { };
  83. }
  84. /* is_tables */
  85. template<typename T>
  86. struct is_tables
  87. : public __impl::is_tables_impl<T>
  88. { };
  89. } }