add iterators

New iterators can be used to iterate through Nodes.

Squashed commit of the following:

commit 602ed679631647dd1c8874b0b0145fcb09458341
Author: GRayHook <s@marinkevich.ru>
Date:   Fri Aug 1 19:36:46 2025 +0700

    fup after CR

commit 08f7b59aa7
Author: GRayHook <s@marinkevich.ru>
Date:   Fri Aug 1 19:20:48 2025 +0700

    normalize members of iterator

commit 038cbb73f4
Author: GRayHook <s@marinkevich.ru>
Date:   Fri Aug 1 18:57:08 2025 +0700

    bump

commit 0f93988fb6
Author: GRayHook <s@marinkevich.ru>
Date:   Fri Aug 1 11:32:35 2025 +0700

    tmp
This commit is contained in:
2025-08-01 19:40:48 +07:00
parent 0f9d73366b
commit f46e1a6d0b
9 changed files with 229 additions and 16 deletions
+34 -16
View File
@@ -1,19 +1,29 @@
#include "nodes/SimpleNode.h"
#include "nodes/ComplexNode.h"
#include <iostream>
#include "Logger.h"
void printTree(const NodePtr& node, int indent = 0) {
if (!node) {
Logger::get("MAIN").err("No node");
return;
}
#include "nodes/SimpleNode.h"
#include "nodes/ComplexNode.h"
#include "iterators/Traversal.h"
for (int i = 0; i < indent; ++i) std::cout << " ";
std::cout << node->name() << "\n";
for (const auto& child : node->children())
printTree(child, indent + 1);
void printNode(INode& node, size_t level) {
for (size_t i = level; i > 0; i--)
std::cout << " ";
std::cout << node.name() << "\n";
}
void printTreeBFS(INode& node) {
for (auto& child : traversal::BFS(&node))
printNode(*child, 0);
}
void printTreeList(INode& node) {
for (auto& child : traversal::DFS(&node))
printNode(*child, 0);
}
void printTreeLadder(INode& node) {
for (auto& [child, level] : traversal::DFS(&node))
printNode(*child, level);
}
int main() {
@@ -31,7 +41,7 @@ int main() {
root->linkChild(child1);
std::cout << "\nInit tree:\n";
printTree(root);
printTreeLadder(*root);
std::cout << "\n";
{
@@ -83,21 +93,29 @@ int main() {
}
std::cout << "\nAnother tree:\n";
printTree(root);
printTreeLadder(*root);
std::cout << "\n";
std::cout << "\nList:\n";
printTreeList(*root);
std::cout << "\n";
std::cout << "\nBFS:\n";
printTreeBFS(*root);
std::cout << "\n";
logger.info("Unlinking ComplexChild2...\n");
child2->unlinkParent();
std::cout << "\nTree after unlink:\n";
printTree(root);
printTreeLadder(*root);
std::cout << "\n";
logger.info("Put refs of ComplexChild2, ComplexChild3 and its children");
}
std::cout << "\nTree after scope out:\n";
printTree(root);
printTreeLadder(*root);
std::cout << "\n";
logger.info("Unlinking ComplexChild1 and ComplexChild3...\n");
@@ -114,7 +132,7 @@ int main() {
root->linkChild(child4);
std::cout << "\nTree flush and link SimpleChild4:\n";
printTree(root);
printTreeLadder(*root);
std::cout << "\n";
}