Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
fatal change for remove interface
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilKleistGao committed Oct 30, 2021
1 parent b930ebf commit c6a311c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions kernel/objects/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ void Object::addChild(const std::string& name, EntityObject* object) {
object->setParent(this);
}

void Object::removeChild(const std::string& name) {
auto it = this->_children.find(name);
Object* object = nullptr;
if (it != this->_children.end()) {
object = it->second;
this->_children.erase(it);
}
void Object::removeChild(Object* child) {
if (child != nullptr) {
bool flag = false;
for (auto it = _children.begin(); it != _children.end(); ++it) {
if (it->second == child) {
flag = true;
_children.erase(it);
break;
}
}

if (object != nullptr) {
object->removeReference();
object->setParent(nullptr);
if (flag) {
child->removeReference();
child->setParent(nullptr);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/objects/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Object : public memory::AutoCollectionObject, public UpdatableObject {
* Remove a reference of a child. If child is not found, nothing
* @param name: the name of child
*/
void removeChild(const std::string& name);
void removeChild(Object* child);

/**
* Remove all children by given name.
Expand Down

0 comments on commit c6a311c

Please sign in to comment.