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.
 
 
 

98 line
2.3 KiB

  1. #pragma once
  2. #include <map>
  3. #include "../tables/table.h"
  4. #include "../tables/tables.h"
  5. namespace cpphibernate {
  6. namespace mariadb {
  7. /**
  8. * @brief Class to wrapp all values needed by the maraidb schema.
  9. */
  10. struct schema_t
  11. {
  12. public:
  13. using table_map = std::map<size_t, const table_t *>;
  14. using field_map = std::map<size_t, const field_t *>;
  15. private:
  16. table_map _table_lookup; //!< dataset id to table pointer map
  17. field_map _field_lookup; //!< field id to field pointer map
  18. public:
  19. std::string name; //!< name of the schema
  20. tables_t tables; //!< tables that are managed by this schema.
  21. public:
  22. /**
  23. * @brief Default constructor.
  24. */
  25. inline schema_t() = default;
  26. /**
  27. * @brief Value constructor.
  28. *
  29. * @param[in] p_schema Cpphibernate schema to create mariadb schema from.
  30. */
  31. template<typename T_schema>
  32. inline schema_t(const T_schema& p_schema);
  33. /**
  34. * @brief Move constructor.
  35. */
  36. inline schema_t(schema_t&&) = delete;
  37. /**
  38. * @brief Copy constructor.
  39. */
  40. inline schema_t(const schema_t&) = delete;
  41. /**
  42. * @brief Print the schema to the passed stream.
  43. */
  44. std::ostream& print(std::ostream& os) const;
  45. /**
  46. * @brief Initialize the whole schema using the passed context.
  47. */
  48. void init(const init_context& context) const;
  49. /**
  50. * @brief Find the table for the passed dataset id in the schema.
  51. */
  52. const table_t& table(size_t dataset_id) const;
  53. /**
  54. * @brief Find the field for the passed field id in the schema.
  55. */
  56. const field_t& field(size_t field_id) const;
  57. private:
  58. /**
  59. * @brief Initialize the field.
  60. */
  61. void init();
  62. };
  63. using schema_ptr_u = std::unique_ptr<const schema_t>;
  64. namespace __impl
  65. {
  66. /**
  67. * @brief Helper type to build schema.
  68. */
  69. template<typename X, typename = void>
  70. struct schema_builder;
  71. }
  72. /**
  73. * @brief Predicate to create mariadb schema class.
  74. */
  75. constexpr decltype(auto) make_schema = mp::generic_predicate<__impl::schema_builder> { };
  76. } }