#ifndef SCHEMA_NODE_HPP #define SCHEMA_NODE_HPP #include "matador/object/attribute_definition_generator.hpp" #include "matador/object/object_info.hpp" #include "matador/object/primary_key_resolver.hpp" #include namespace matador::object { class basic_object_info; class schema; class schema_node final { public: using node_ptr = std::shared_ptr; template < typename Type > static std::shared_ptr make_node(object::schema& tree, const std::string& name) { auto node = std::shared_ptr(new schema_node(tree, name)); primary_key_resolver resolver; auto pk_info = resolver.resolve(); auto info = std::make_unique>( node, std::move(pk_info.pk), std::make_shared(pk_info.pk_column_name, name, pk_info.type, utils::constraints::FOREIGN_KEY), object_definition{attribute_definition_generator::generate(tree)} ); node->info_ = std::move(info); return node; } template < typename Type > static std::shared_ptr make_relation_node(object::schema& tree, const std::string& name) { auto node = std::shared_ptr(new schema_node(tree, name)); auto info = std::make_unique>( node, object_definition{attribute_definition_generator::generate(tree)} ); node->info_ = std::move(info); return node; } static std::shared_ptr make_null_node(schema& tree); schema_node(const schema_node& other) = delete; schema_node(schema_node&& other) = default; schema_node& operator=(const schema_node& other) = delete; schema_node& operator=(schema_node&& other) = delete; ~schema_node() = default; [[nodiscard]] std::string name() const; [[nodiscard]] std::type_index type_index() const; [[nodiscard]] node_ptr next() const; [[nodiscard]] node_ptr prev() const; [[nodiscard]] const basic_object_info& basic_info() const; void update_name(const std::string& name); template object_info_ref info() const { return std::ref(static_cast&>(*info_)); } const object::schema& schema() const; private: explicit schema_node(object::schema& tree); schema_node(object::schema& tree, std::string name); private: friend class schema; template friend class relation_completer; friend class const_schema_node_iterator; object::schema &schema_; std::unique_ptr info_; std::shared_ptr parent_; std::shared_ptr previous_sibling_; std::shared_ptr next_sibling_; std::shared_ptr first_child_; std::shared_ptr last_child_; std::string name_; size_t depth_{0}; }; } #endif //SCHEMA_NODE_HPP