Warning iterator invalidation in removeEntity

This commit is contained in:
fluider
2020-09-30 09:38:01 +02:00
committed by Thomas Krijnen
parent b4f4d9b3c5
commit e3831be16e
+9 -1
View File
@@ -1763,6 +1763,14 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
void IfcFile::removeEntity(IfcUtil::IfcBaseClass* entity) {
const unsigned id = entity->data().id();
IfcUtil::IfcBaseClass* file_entity = instance_by_id(id);
// Attention when running removeEntity inside a loop over a list of entities to be removed.
// This invalidates the iterator. A workaround is to reverse the loop:
// boost::shared_ptr<IfcEntityList> entities = ...;
// for (auto it = entities->end() - 1; it >= entities->begin(); --it) {
// IfcUtil::IfcBaseClass *const inst = *it;
// model->removeEntity(inst);
// }
// TODO: Create a set of weak relations. Inverse relations that do not dictate an
// instance to be retained. For example: when deleting an IfcRepresentation, the
@@ -2173,4 +2181,4 @@ void IfcParse::IfcFile::build_inverses() {
for (auto& pair : *this) {
build_inverses_(pair.second);
}
}
}