#include #include "matador/object/schema_node.hpp" namespace matador::object { schema_node::schema_node(object::schema &tree) : schema_(tree) , info_(std::make_unique(*this, object_definition{})) {} std::string schema_node::name() const { return name_; } std::type_index schema_node::type_index() const { return info_->type_index(); } const basic_object_info& schema_node::basic_info() const { return *info_; } schema_node::node_ptr schema_node::next() const { // if we have a child, child is the next iterator to return // (if we don't do iterate over the siblings) if (first_child_ && first_child_->next_sibling_ != last_child_) { return first_child_->next_sibling_; } // if there is no child, we check for sibling // if there is a sibling, this is our next iterator to return // if not, we go back to the parent auto *node = this; while (node->parent_ && node->next_sibling_ == node->parent_->last_child_) { node = node->parent_.get(); } return node->parent_ ? node->next_sibling_ : node->last_child_; } schema_node::node_ptr schema_node::prev() const { // if node has a previous sibling, we set it // as our next iterator. then we check if there // are last children. if so, we set the last-last // child as our iterator if (previous_sibling_ && previous_sibling_->previous_sibling_) { auto node = previous_sibling_; while (node->last_child_ && node->first_child_->next_sibling_ != node->last_child_) { node = node->last_child_->previous_sibling_; } return node; } // if there is no previous sibling, our next iterator // is the parent of the node return parent_->parent_ ? parent_ : parent_->first_child_->next_sibling_; } }