|
- #pragma once
-
- #include <vector>
- #include <memory>
- #include <cpphibernate/config.h>
-
- #include "../forward.h"
- #include "../fields/fields.h"
-
- namespace cpphibernate {
- namespace mariadb {
-
- /**
- * @brief Abstract table class.
- */
- struct table_t
- {
- public:
- using size_vector = std::vector<size_t>; //!< vector of size_t
- using table_vector = std::vector<const table_t *>; //!< vector of constant field pointers
- using field_vector = std::vector<const field_t *>; //!< vector of constant field pointers
- using field_map = std::map<size_t, const field_t *>; //!< map of field id to field
-
- private:
- field_map _lookup; //!< field id to field pointer map
-
- public:
- size_t id { 0 }; //!< unique id of the table assigned by the user
- size_t dataset_id { 0 }; //!< unique id of the dataset type
- size_t base_dataset_id { 0 }; //!< unique id of the dataset type
- size_vector derived_dataset_ids; //!< vector of ids of all derived dataset
-
- bool is_used_in_container { false }; //!< indicates if this table is used inside a container
-
- std::string name; //!< name of the table
- const schema_t& schema; //!< schema this table is owned by
- fields_t fields; //!< vector of fields managed by this table
-
- const table_t * base_table { nullptr }; //!< base table (if has one)
- table_vector derived_tables; //!< vector of pointers of all derived tables
-
- const field_t * primary_key_field { nullptr }; //!< primary key field
- field_vector foreign_key_fields; //!< vector of pointers of all foreign key fields
- field_vector foreign_table_fields; //!< vector of pointers of all foreign table fields
- field_vector foreign_table_one_fields; //!< vector of pointers of all foreign table one fields
- field_vector foreign_table_many_fields; //!< vector of pointers of all foreign table many fields
- field_vector data_fields; //!< vector of pointers of all normal data fields
-
- public:
- /**
- * @brief Default constructor.
- */
- inline table_t() = default;
-
- /**
- * @brief Value constructor. Creates a mariadb table from the cpphibernate table.
- *
- * @param[in] p_owner Owner of the table.
- * @param[in] p_schema Cpphibernate schema the table belongs to.
- * @param[in] p_table Cpphibernate table to create mariadb table for.
- */
- template<
- typename T_schema,
- typename T_table>
- inline table_t(
- const schema_t& p_owner,
- const T_schema& p_schema,
- const T_table& p_table);
-
- /**
- * @brief Move constructor.
- */
- inline table_t(table_t&& other) = delete;
-
- /**
- * @brief Copy constructor.
- */
- inline table_t(const table_t&) = delete;
-
- /**
- * @brief Destructor.
- */
- virtual ~table_t() = 0;
-
- /**
- * @brief Print the table to the passed stream.
- */
- std::ostream& print(std::ostream& os) const;
-
- private:
- /**
- * @brief Initialize the field.
- */
- void init();
- };
-
- namespace __impl
- {
-
- /**
- * @brief Helper type to build table.
- */
- template<typename X, typename = void>
- struct table_builder;
-
- }
-
- /**
- * @brief Predicate to create mariadb table class.
- */
- constexpr decltype(auto) make_table = mp::generic_predicate<__impl::table_builder> { };
-
- } }
-
- #include "table.inl"
|