#include #include "matador/object/schema_node.hpp" namespace matador::object { schema_node::schema_node(schema &tree) : schema_(tree) , info_(std::make_unique(*this)) {} std::string schema_node::name() const { return name_; } std::type_index schema_node::type_index() const { return info_->type_index(); } void schema_node::append(const std::shared_ptr &sibling) { sibling->parent_ = parent_; // sibling->previous_sibling_ = this; // sibling->next_sibling_ = next_sibling_; // next_sibling_ = sibling; // sibling->next_sibling_->previous_sibling_ = sibling; // sibling->depth = depth; // if (!parent_) { // sibling->op_first = new object_proxy(); // sibling->op_last = sibling->op_marker = new object_proxy(); // sibling->op_first->link(sibling->op_last); // } else { // throw object_exception("failed to add node as sibling: node has no parent"); // } } void schema_node::insert(const std::shared_ptr &child) { // child->parent_ = this; // child->previous_sibling_ = last_child_->previous_sibling_; // child->next_sibling_ = last_child_; // last_child_->previous_sibling_->next_sibling_ = child; // last_child_->previous_sibling_ = child; // set depth // child->depth = depth + 1; // set object proxy pointer // 1. first // if (op_first->next() == op_last) { // // node hasn't any serializable (proxy) // child->op_first = op_first; // } else { // // node has some objects (proxy) // child->op_first = op_last->prev(); // } // // 2. marker // child->op_marker = op_last; // // 3. last // child->op_last = op_last; } 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_; } }