Add index to EntryState (#933)

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Herring
2024-09-30 23:18:59 +02:00
committed by GitHub
parent dfb9558eaf
commit 1d40687a40
9 changed files with 74 additions and 22 deletions

View File

@@ -51,6 +51,22 @@ size_t ComponentBase::ChildCount() const {
return children_.size();
}
/// @brief Return index of the component in its parent. -1 if no parent.
/// @ingroup component
int ComponentBase::Index() const {
if (parent_ == nullptr) {
return -1;
}
int index = 0;
for (const Component& child : parent_->children_) {
if (child.get() == this) {
return index;
}
index++;
}
return -1; // Not reached.
}
/// @brief Add a child.
/// @@param child The child to be attached.
/// @ingroup component