Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

68 строки
2.0 KiB

  1. #pragma once
  2. #include "base_context.h"
  3. namespace cpphibernate {
  4. namespace mariadb {
  5. namespace __impl
  6. {
  7. /**
  8. * @brief Helper class to create the change_context predicate.
  9. */
  10. template<typename X, typename = void>
  11. struct change_context_builder;
  12. }
  13. /**
  14. * @brief Predicate to change the stored dataset of any data_context.
  15. */
  16. constexpr decltype(auto) change_context = cppmp::generic_predicate<__impl::change_context_builder> { };
  17. /**
  18. * @brief Mariadb driver context that helds a specific dataset.
  19. */
  20. struct data_context
  21. : public base_context
  22. {
  23. private:
  24. mutable size_t _dataset_id; //!< Unique type id of the dataset that is stored in this context.
  25. mutable void * _dataset; //!< Pointer to the stored dataset.
  26. mutable const table_t * _table; //!< Table this context/dataset belongs to
  27. template<typename X, typename T_enable>
  28. friend struct __impl::change_context_builder;
  29. public:
  30. /**
  31. * @brief Constructor.
  32. *
  33. * @param[in] p_schema Mariadb driver schema to use for the operation.
  34. * @param[in] p_connection Mariadb connection to execute queries with.
  35. * @param[in] p_dataset Dataset to store in the context.
  36. */
  37. template<typename T_dataset>
  38. inline data_context(
  39. const schema_t& p_schema,
  40. ::cppmariadb::connection& p_connection,
  41. T_dataset& p_dataset);
  42. /**
  43. * @brief Get a reference to the stored dataset if the type matches.
  44. * If an invalid type is requested an exception is thrown.
  45. */
  46. template<typename T_dataset>
  47. inline decltype(auto) get() const;
  48. private:
  49. /**
  50. * @brief Set the dataset that is stored in this context.
  51. */
  52. template<typename T_dataset>
  53. inline void set(T_dataset& dataset);
  54. };
  55. } }