Skip to content

Commit

Permalink
LibCore: Add CObject::for_each_child(callback).
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed May 27, 2019
1 parent 3654c33 commit 906fde8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions LibCore/CObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(CObject&)> invokee)
Expand Down
9 changes: 9 additions & 0 deletions LibCore/CObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ class CObject : public Weakable<CObject> {
Vector<CObject*>& children() { return m_children; }
const Vector<CObject*>& children() const { return m_children; }

template<typename Callback>
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; }

Expand Down

0 comments on commit 906fde8

Please sign in to comment.