|
- #pragma once
-
- #include <map>
-
- #include "../tables/table.h"
- #include "../tables/tables.h"
-
- namespace cpphibernate {
- namespace mariadb {
-
- /**
- * @brief Class to wrapp all values needed by the maraidb schema.
- */
- struct schema_t
- {
- public:
- using table_map = std::map<size_t, const table_t *>;
- using field_map = std::map<size_t, const field_t *>;
-
- private:
- table_map _table_lookup; //!< dataset id to table pointer map
- field_map _field_lookup; //!< field id to field pointer map
-
- public:
- std::string name; //!< name of the schema
- tables_t tables; //!< tables that are managed by this schema.
-
- public:
- /**
- * @brief Default constructor.
- */
- inline schema_t() = default;
-
- /**
- * @brief Value constructor.
- *
- * @param[in] p_schema Cpphibernate schema to create mariadb schema from.
- */
- template<typename T_schema>
- inline schema_t(const T_schema& p_schema);
-
- /**
- * @brief Move constructor.
- */
- inline schema_t(schema_t&&) = delete;
-
- /**
- * @brief Copy constructor.
- */
- inline schema_t(const schema_t&) = delete;
-
- /**
- * @brief Print the schema to the passed stream.
- */
- std::ostream& print(std::ostream& os) const;
-
- /**
- * @brief Initialize the whole schema using the passed context.
- */
- void init(const init_context& context) const;
-
- /**
- * @brief Find the table for the passed dataset id in the schema.
- */
- const table_t& table(size_t dataset_id) const;
-
- /**
- * @brief Find the field for the passed field id in the schema.
- */
- const field_t& field(size_t field_id) const;
-
- private:
- /**
- * @brief Initialize the field.
- */
- void init();
- };
-
- using schema_ptr_u = std::unique_ptr<const schema_t>;
-
- namespace __impl
- {
-
- /**
- * @brief Helper type to build schema.
- */
- template<typename X, typename = void>
- struct schema_builder;
-
- }
-
- /**
- * @brief Predicate to create mariadb schema class.
- */
- constexpr decltype(auto) make_schema = mp::generic_predicate<__impl::schema_builder> { };
-
- } }
|