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.
 
 
 

55 lines
1.9 KiB

  1. #pragma once
  2. #include <cpphibernate/driver/mariadb/schema/fields.h>
  3. beg_namespace_cpphibernate_driver_mariadb
  4. {
  5. namespace __impl
  6. {
  7. /* make_fields_impl */
  8. template<typename T, typename>
  9. struct make_fields_impl
  10. {
  11. template<typename... T_args>
  12. static constexpr decltype(auto) apply(T_args&&... args)
  13. { static_assert(sizeof...(args) == -1, "Invalid parameters for mariadb::make_fields(...)!"); }
  14. };
  15. template<typename T_schema, typename T_table>
  16. struct make_fields_impl<
  17. mp::list<T_schema, T_table>,
  18. mp::enable_if_c<
  19. schema::is_schema<mp::decay_t<T_schema>>::value
  20. && schema::is_table <mp::decay_t<T_table >>::value>>
  21. {
  22. template<typename T_index>
  23. static constexpr void emplace(fields_t& fields, const T_schema& schema, const T_table& table, T_index&& index)
  24. {
  25. decltype(auto) field = make_field(schema, table, table.fields[index]);
  26. using field_type = mp::decay_t<decltype(field)>;
  27. fields.emplace_back(new field_type(std::move(field)));
  28. }
  29. template<size_t... I>
  30. static auto helper(const T_schema& schema, const T_table& table, std::index_sequence<I...>&&)
  31. {
  32. fields_t fields;
  33. int dummy[] = {0, (emplace(fields, schema, table, hana::size_c<I>), void(), 0)...};
  34. (void) dummy;
  35. return fields;
  36. }
  37. static constexpr decltype(auto) apply(const T_schema& schema, const T_table& table)
  38. {
  39. using size = decltype(hana::size(table.fields));
  40. return helper(schema, table, std::make_index_sequence<size::value> { });
  41. }
  42. };
  43. }
  44. }
  45. end_namespace_cpphibernate_driver_mariadb