query/include/matador/object/schema_node.hpp

62 lines
1.6 KiB
C++

#ifndef SCHEMA_NODE_HPP
#define SCHEMA_NODE_HPP
#include "matador/object/attribute_definition_generator.hpp"
#include "matador/object/object_info.hpp"
#include <memory>
namespace matador::object {
class basic_object_info;
class schema;
class schema_node final {
public:
using node_ptr = std::shared_ptr<schema_node>;
static std::shared_ptr<schema_node> make_node(schema& tree, const std::string& name, std::unique_ptr<basic_object_info> &&info);
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;
template <typename Type>
object_info_ref<Type> info() const {
return std::ref(static_cast<const object_info<Type>&>(*info_));
}
private:
explicit schema_node(schema& tree);
schema_node(schema& tree, std::string name, std::unique_ptr<basic_object_info> &&info);
private:
friend class schema;
friend class const_schema_node_iterator;
object::schema &schema_;
std::unique_ptr<basic_object_info> info_;
std::shared_ptr<schema_node> parent_;
std::shared_ptr<schema_node> previous_sibling_;
std::shared_ptr<schema_node> next_sibling_;
std::shared_ptr<schema_node> first_child_;
std::shared_ptr<schema_node> last_child_;
std::string name_;
size_t depth_{0};
};
}
#endif //SCHEMA_NODE_HPP