|
- #pragma once
-
- #include <cpphibernate/config.h>
- #include <cpphibernate/misc/type_helper.h>
- #include <cpphibernate/misc/equality_compare.h>
-
- namespace cpphibernate {
- namespace schema {
-
- namespace __impl
- {
-
- /**
- * @brief Tag class to mark field types.
- */
- struct tag_field
- { };
-
- /**
- * @brief Represents a data field in the schema.
- *
- * @tparam T_name Type of the name of the field.
- * @tparam T_getter Type of the getter of the field.
- * @tparam T_setter Type of the setter of the field.
- * @tparam T_attributes Type of the attributes of the field.
- */
- template<typename T_name, typename T_getter, typename T_setter, typename T_attributes>
- struct field_t
- : public tag_field
- , public tag_equality_comparable<tag_field>
- {
- using name_type = T_name;
- using getter_type = T_getter;
- using setter_type = T_setter;
- using dataset_type = typename mp::decay_t<getter_type>::object_type;
- using real_dataset_type = real_dataset_t<dataset_type>;
- using value_type = typename mp::decay_t<getter_type>::value_type;
- using real_value_type = real_dataset_t<value_type>;
- using attributes_type = T_attributes;
- using this_type = field_t<name_type, getter_type, setter_type, attributes_type>;
-
- name_type name; //!< Name of the field.
- getter_type getter; //!< Getter of the field, to get values from the dataset.
- setter_type setter; //!< Setter of the field, to set values of the dataset.
- attributes_type attributes; //!< List of attributes for this field.
-
- hana::type<value_type> wrapped_value_type; //!< Type of the stoed value.
- hana::type<dataset_type> wrapped_dataset_type; //!< Type of the real stored value (containers are removed).
- hana::type<real_value_type> wrapped_real_value_type; //!< Type of the dataset this fields uses.
- hana::type<real_dataset_type> wrapped_real_dataset_type; //!< Type of the read dataset (contaiers are removed).
-
- /**
- * @brief Constrcutor.
- *
- * @param[in] p_name Name of the field.
- * @param[in] p_getter Getter to receive the represented value from the dataset.
- * @param[in] p_setter Setter to set the represented value at the dataset.
- * @param[in] p_attributes List of attributes of the field.
- */
- constexpr field_t(
- T_name&& p_name,
- T_getter&& p_getter,
- T_setter&& p_setter,
- T_attributes&& p_attributes);
-
- /**
- * @brief Move constructor.
- */
- constexpr field_t(field_t&&) = default;
-
- /**
- * @brief Copy constructor.
- */
- constexpr field_t(const field_t&) = delete;
-
- /**
- * @brief Move assignment constructor.
- */
- constexpr field_t& operator = (field_t&&) = default;
-
- /**
- * @brief Copy assignment constructor.
- */
- constexpr field_t& operator = (const field_t&) = delete;
-
- /**
- * @brief Print the field to the passed stream.
- */
- inline void print(std::ostream& os) const;
- };
-
- /**
- * @brief Helper type to build field objects.
- */
- template<typename X, typename = void>
- struct field_builder;
-
- }
-
- /**
- * @brief Evaluates to true_t if the passed type is a field type.
- */
- template<typename T>
- struct is_field;
-
- /**
- * @brief Is true if the passed type is an attributes type, false otherwise.
- */
- template<typename T>
- constexpr bool is_field_v = is_field<T>::value;
-
- /**
- * @brief Predicate to create an field object from the passed attributes.
- */
- constexpr decltype(auto) make_field = mp::generic_predicate<__impl::field_builder> { };
-
- } }
-
- #include "field.inl"
|