|
- #pragma once
-
- #include <cpphibernate/config.h>
-
- #include "base_context.h"
-
- namespace cpphibernate {
- namespace mariadb {
-
- namespace __impl
- {
-
- /**
- * @brief Helper class to create the change_context predicate.
- */
- template<typename X, typename = void>
- struct change_context_builder;
-
- }
-
- struct table_t;
-
- /**
- * @brief Predicate to change the stored dataset of any data_context.
- */
- constexpr decltype(auto) change_context = cppmp::generic_predicate<__impl::change_context_builder> { };
-
- /**
- * @brief Mariadb driver context that helds a specific dataset.
- */
- struct data_context
- : public base_context
- {
- private:
- mutable size_t _dataset_id; //!< Unique type id of the dataset that is stored in this context.
- mutable void * _dataset; //!< Pointer to the stored dataset.
- mutable const table_t * _table; //!< Table this context/dataset belongs to
-
- template<typename X, typename T_enable>
- friend struct __impl::change_context_builder;
-
- protected:
- /**
- * @brief Constructor.
- *
- * @param[in] p_schema Mariadb driver schema to use for the operation.
- * @param[in] p_connection Mariadb connection to execute queries with.
- */
- inline data_context(
- const schema_t& p_schema,
- ::cppmariadb::connection& p_connection);
-
- public:
- /**
- * @brief Constructor.
- *
- * @param[in] p_schema Mariadb driver schema to use for the operation.
- * @param[in] p_connection Mariadb connection to execute queries with.
- * @param[in] p_dataset Dataset to store in the context.
- */
- template<typename T_dataset>
- inline data_context(
- const schema_t& p_schema,
- ::cppmariadb::connection& p_connection,
- T_dataset& p_dataset);
-
- /**
- * @brief Get a reference to the stored dataset if the type matches.
- * If an invalid type is requested an exception is thrown.
- */
- template<typename T_dataset>
- inline decltype(auto) get() const;
-
- protected:
- /**
- * @brief Set the dataset that is stored in this context.
- *
- * @param[in] dataset Dataset to store in the context.
- * @param[in] dataset_id Unique id of the dataset stored in the context.
- *
- * @return Pointer to the stored dataset.
- */
- template<typename T_dataset>
- inline void * set(T_dataset& dataset, size_t dataset_id = 0) const;
-
- /**
- * @brief Clear the context (set the stored dataset to nullptr).
- */
- inline void clear() const;
- };
-
- } }
|