#pragma once #include #include "base_context.h" namespace cpphibernate { namespace mariadb { namespace __impl { /** * @brief Helper class to create the change_context predicate. */ template 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 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 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 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 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; }; } }