Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

116 righe
4.1 KiB

  1. #pragma once
  2. #include <vector>
  3. #include <memory>
  4. #include <cpphibernate/config.h>
  5. #include "../forward.h"
  6. #include "../fields/fields.h"
  7. namespace cpphibernate {
  8. namespace mariadb {
  9. /**
  10. * @brief Abstract table class.
  11. */
  12. struct table_t
  13. {
  14. public:
  15. using size_vector = std::vector<size_t>; //!< vector of size_t
  16. using table_vector = std::vector<const table_t *>; //!< vector of constant field pointers
  17. using field_vector = std::vector<const field_t *>; //!< vector of constant field pointers
  18. using field_map = std::map<size_t, const field_t *>; //!< map of field id to field
  19. private:
  20. field_map _lookup; //!< field id to field pointer map
  21. public:
  22. size_t id { 0 }; //!< unique id of the table assigned by the user
  23. size_t dataset_id { 0 }; //!< unique id of the dataset type
  24. size_t base_dataset_id { 0 }; //!< unique id of the dataset type
  25. size_vector derived_dataset_ids; //!< vector of ids of all derived dataset
  26. bool is_used_in_container { false }; //!< indicates if this table is used inside a container
  27. std::string name; //!< name of the table
  28. const schema_t& schema; //!< schema this table is owned by
  29. fields_t fields; //!< vector of fields managed by this table
  30. const table_t * base_table { nullptr }; //!< base table (if has one)
  31. table_vector derived_tables; //!< vector of pointers of all derived tables
  32. const field_t * primary_key_field { nullptr }; //!< primary key field
  33. field_vector foreign_key_fields; //!< vector of pointers of all foreign key fields
  34. field_vector foreign_table_fields; //!< vector of pointers of all foreign table fields
  35. field_vector foreign_table_one_fields; //!< vector of pointers of all foreign table one fields
  36. field_vector foreign_table_many_fields; //!< vector of pointers of all foreign table many fields
  37. field_vector data_fields; //!< vector of pointers of all normal data fields
  38. public:
  39. /**
  40. * @brief Default constructor.
  41. */
  42. inline table_t() = default;
  43. /**
  44. * @brief Value constructor. Creates a mariadb table from the cpphibernate table.
  45. *
  46. * @param[in] p_owner Owner of the table.
  47. * @param[in] p_schema Cpphibernate schema the table belongs to.
  48. * @param[in] p_table Cpphibernate table to create mariadb table for.
  49. */
  50. template<
  51. typename T_schema,
  52. typename T_table>
  53. inline table_t(
  54. const schema_t& p_owner,
  55. const T_schema& p_schema,
  56. const T_table& p_table);
  57. /**
  58. * @brief Move constructor.
  59. */
  60. inline table_t(table_t&& other) = delete;
  61. /**
  62. * @brief Copy constructor.
  63. */
  64. inline table_t(const table_t&) = delete;
  65. /**
  66. * @brief Destructor.
  67. */
  68. virtual ~table_t() = 0;
  69. /**
  70. * @brief Print the table to the passed stream.
  71. */
  72. std::ostream& print(std::ostream& os) const;
  73. private:
  74. /**
  75. * @brief Initialize the field.
  76. */
  77. void init();
  78. };
  79. namespace __impl
  80. {
  81. /**
  82. * @brief Helper type to build table.
  83. */
  84. template<typename X, typename = void>
  85. struct table_builder;
  86. }
  87. /**
  88. * @brief Predicate to create mariadb table class.
  89. */
  90. constexpr decltype(auto) make_table = mp::generic_predicate<__impl::table_builder> { };
  91. } }
  92. #include "table.inl"