Moves the iterator to the next node in the tree. If we are at the end, do nothing, otherwise if our current node has children, use the children iterator and push the current node into the stack. If we reach the end of the local iterator, pop it.
| 89 | // current node into the stack. |
| 90 | // If we reach the end of the local iterator, pop it. |
| 91 | inline void MoveToNextNode() { |
| 92 | if (!current_) return; |
| 93 | if (parent_iterators_.empty()) { |
| 94 | current_ = nullptr; |
| 95 | return; |
| 96 | } |
| 97 | std::pair<NodePtr, NodeIterator>& next_it = parent_iterators_.top(); |
| 98 | // Set the new node. |
| 99 | current_ = *next_it.second; |
| 100 | // Update the iterator for the next child. |
| 101 | ++next_it.second; |
| 102 | // If we finished with node, pop it. |
| 103 | if (next_it.first->end() == next_it.second) parent_iterators_.pop(); |
| 104 | // If our current node is not a leaf, store the iteration state for later. |
| 105 | if (current_->begin() != current_->end()) |
| 106 | parent_iterators_.emplace(make_pair(current_, current_->begin())); |
| 107 | } |
| 108 | |
| 109 | // The current node of the tree. |
| 110 | NodePtr current_; |