選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

127 行
4.1 KiB

  1. #pragma once
  2. #include <cpphibernate/config.h>
  3. #include <cpphibernate/misc/type_helper.h>
  4. #include <cpphibernate/misc/equality_compare.h>
  5. namespace cpphibernate {
  6. namespace schema {
  7. namespace __impl
  8. {
  9. /**
  10. * @brief Tag class to mark table objects.
  11. */
  12. struct tag_table
  13. { };
  14. /**
  15. * @brief Represents a data field in the schema.
  16. *
  17. * @tparam T_name Name of the table.
  18. * @tparam T_wrapped_dataset Dataset type the table represents.
  19. * @tparam T_table_id Unique ID assigned by the user.
  20. * @tparam T_fields List of field that belongs to the table.
  21. */
  22. template<
  23. typename T_name,
  24. typename T_wrapped_dataset,
  25. typename T_table_id,
  26. typename T_fields>
  27. struct table_t
  28. : public tag_table
  29. , public tag_equality_comparable<tag_table>
  30. {
  31. using name_type = T_name;
  32. using wrapped_dataset_type = mp::decay_t<T_wrapped_dataset>;
  33. using dataset_type = decay_unwrap_t<wrapped_dataset_type>;
  34. using table_id_type = T_table_id;
  35. using fields_type = T_fields;
  36. using this_type = table_t<name_type, wrapped_dataset_type, table_id_type, fields_type>;
  37. name_type name; //!< Name of the table.
  38. wrapped_dataset_type wrapped_dataset; //!< Dataset type this table represents.
  39. table_id_type table_id; //!< Unique ID of the table, assigned by the user.
  40. fields_type fields; //!< List of fields that belongs to the table.
  41. /**
  42. * @brief Constructor.
  43. *
  44. * @param[in] p_name Name of the table.
  45. * @param[in] p_wrapped_dataset Dataset type this table represents.
  46. * @param[in] p_table_id Unique ID of the table assigned by the user.
  47. * @param[in] p_fields List of fields that belongs to the table.
  48. */
  49. constexpr table_t(
  50. name_type p_name,
  51. wrapped_dataset_type p_wrapped_dataset,
  52. table_id_type p_table_id,
  53. fields_type p_fields);
  54. /**
  55. * @brief Move constructor.
  56. */
  57. constexpr table_t(table_t&&) = default;
  58. /**
  59. * @brief Copy constructor.
  60. */
  61. constexpr table_t(const table_t&) = delete;
  62. /**
  63. * @brief Move assignment constructor.
  64. */
  65. constexpr table_t& operator = (table_t&&) = default;
  66. /**
  67. * @brief Copy assignment constructor.
  68. */
  69. constexpr table_t& operator = (const table_t&) = delete;
  70. /**
  71. * @brief Print the table to the passed stream.
  72. */
  73. inline void print(std::ostream& os) const;
  74. };
  75. /**
  76. * @brief Helper type to build table objects.
  77. */
  78. template<typename X, typename = void>
  79. struct table_builder;
  80. /**
  81. * @brief Helper type to get the wrapped dataset of the passed table.
  82. */
  83. template<typename X, typename = void>
  84. struct table_get_wrapped_dataset;
  85. }
  86. /**
  87. * @brief Evaluates to true_t if the passed type is a table type.
  88. */
  89. template<typename T>
  90. struct is_table;
  91. /**
  92. * @brief Is true if the passed type is an attributes type, false otherwise.
  93. */
  94. template<typename T>
  95. constexpr bool is_table_v = is_table<T>::value;
  96. /**
  97. * @brief Predicate to create an table object from the passed attributes.
  98. */
  99. constexpr decltype(auto) make_table = mp::generic_predicate<__impl::table_builder> { };
  100. /**
  101. * @brief Predicate to get the wrapped dataset of the passed table.
  102. */
  103. constexpr decltype(auto) get_wrapped_dataset = mp::generic_predicate<__impl::table_get_wrapped_dataset> { };
  104. } }
  105. #include "table.inl"