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.
 
 
 

120 line
4.3 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 field types.
  11. */
  12. struct tag_field
  13. { };
  14. /**
  15. * @brief Represents a data field in the schema.
  16. *
  17. * @tparam T_name Type of the name of the field.
  18. * @tparam T_getter Type of the getter of the field.
  19. * @tparam T_setter Type of the setter of the field.
  20. * @tparam T_attributes Type of the attributes of the field.
  21. */
  22. template<typename T_name, typename T_getter, typename T_setter, typename T_attributes>
  23. struct field_t
  24. : public tag_field
  25. , public tag_equality_comparable<tag_field>
  26. {
  27. using name_type = T_name;
  28. using getter_type = T_getter;
  29. using setter_type = T_setter;
  30. using dataset_type = typename mp::decay_t<getter_type>::object_type;
  31. using real_dataset_type = real_dataset_t<dataset_type>;
  32. using value_type = typename mp::decay_t<getter_type>::value_type;
  33. using real_value_type = real_dataset_t<value_type>;
  34. using attributes_type = T_attributes;
  35. using this_type = field_t<name_type, getter_type, setter_type, attributes_type>;
  36. name_type name; //!< Name of the field.
  37. getter_type getter; //!< Getter of the field, to get values from the dataset.
  38. setter_type setter; //!< Setter of the field, to set values of the dataset.
  39. attributes_type attributes; //!< List of attributes for this field.
  40. hana::type<value_type> wrapped_value_type; //!< Type of the stoed value.
  41. hana::type<dataset_type> wrapped_dataset_type; //!< Type of the real stored value (containers are removed).
  42. hana::type<real_value_type> wrapped_real_value_type; //!< Type of the dataset this fields uses.
  43. hana::type<real_dataset_type> wrapped_real_dataset_type; //!< Type of the read dataset (contaiers are removed).
  44. /**
  45. * @brief Constrcutor.
  46. *
  47. * @param[in] p_name Name of the field.
  48. * @param[in] p_getter Getter to receive the represented value from the dataset.
  49. * @param[in] p_setter Setter to set the represented value at the dataset.
  50. * @param[in] p_attributes List of attributes of the field.
  51. */
  52. constexpr field_t(
  53. T_name&& p_name,
  54. T_getter&& p_getter,
  55. T_setter&& p_setter,
  56. T_attributes&& p_attributes);
  57. /**
  58. * @brief Move constructor.
  59. */
  60. constexpr field_t(field_t&&) = default;
  61. /**
  62. * @brief Copy constructor.
  63. */
  64. constexpr field_t(const field_t&) = delete;
  65. /**
  66. * @brief Move assignment constructor.
  67. */
  68. constexpr field_t& operator = (field_t&&) = default;
  69. /**
  70. * @brief Copy assignment constructor.
  71. */
  72. constexpr field_t& operator = (const field_t&) = delete;
  73. /**
  74. * @brief Print the field to the passed stream.
  75. */
  76. inline void print(std::ostream& os) const;
  77. };
  78. /**
  79. * @brief Helper type to build field objects.
  80. */
  81. template<typename X, typename = void>
  82. struct field_builder;
  83. }
  84. /**
  85. * @brief Evaluates to true_t if the passed type is a field type.
  86. */
  87. template<typename T>
  88. struct is_field;
  89. /**
  90. * @brief Is true if the passed type is an attributes type, false otherwise.
  91. */
  92. template<typename T>
  93. constexpr bool is_field_v = is_field<T>::value;
  94. /**
  95. * @brief Predicate to create an field object from the passed attributes.
  96. */
  97. constexpr decltype(auto) make_field = mp::generic_predicate<__impl::field_builder> { };
  98. } }
  99. #include "field.inl"