diff --git a/LibCore/CObject.cpp b/LibCore/CObject.cpp index 850407a012..93f7733c92 100644 --- a/LibCore/CObject.cpp +++ b/LibCore/CObject.cpp @@ -100,9 +100,10 @@ void CObject::dump_tree(int indent) } printf("%s{%p}\n", class_name(), this); - for (auto* child : children()) { - child->dump_tree(indent + 2); - } + for_each_child([&] (auto& child) { + child.dump_tree(indent + 2); + return IterationDecision::Continue; + }); } void CObject::deferred_invoke(Function invokee) diff --git a/LibCore/CObject.h b/LibCore/CObject.h index e0656b2019..4f12811812 100644 --- a/LibCore/CObject.h +++ b/LibCore/CObject.h @@ -20,6 +20,15 @@ public: Vector& children() { return m_children; } const Vector& children() const { return m_children; } + template + void for_each_child(Callback callback) + { + for (auto* child : m_children) { + if (callback(*child) == IterationDecision::Abort) + return; + } + } + CObject* parent() { return m_parent; } const CObject* parent() const { return m_parent; }