Add IfcParse::clear_schemas() and individual Ifc___::clear_schema() to clear any resource allocated by registered schemas

Add missing virtual destructors in IfcSchema.h
This commit is contained in:
Adrien SCHVALBERG
2022-04-27 16:20:35 +02:00
committed by Thomas Krijnen
parent 93fd3f97e3
commit e677355438
20 changed files with 169 additions and 27 deletions
+42
View File
@@ -37,6 +37,14 @@ bool IfcParse::named_type::is(const IfcParse::declaration& decl) const {
return declared_type()->is(decl);
}
IfcParse::entity::~entity() {
for (auto attribute : attributes_) {
delete attribute;
}
for (auto inverse_attribute : inverse_attributes_) {
delete inverse_attribute;
}
}
static std::map<std::string, const IfcParse::schema_definition*> schemas;
IfcParse::schema_definition::schema_definition(const std::string& name, const std::vector<const declaration*>& declarations, instance_factory* factory)
@@ -61,6 +69,7 @@ IfcParse::schema_definition::~schema_definition() {
for (std::vector<const declaration*>::const_iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
delete *it;
}
delete factory_;
}
IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanceData * data) const {
@@ -149,3 +158,36 @@ std::vector<std::string> IfcParse::schema_names() {
return return_value;
}
void IfcParse::clear_schemas() {
#ifdef HAS_SCHEMA_2x3
Ifc2x3::clear_schema();
#endif
#ifdef HAS_SCHEMA_4
Ifc4::clear_schema();
#endif
#ifdef HAS_SCHEMA_4x1
Ifc4x1::clear_schema();
#endif
#ifdef HAS_SCHEMA_4x2
Ifc4x2::clear_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc1
Ifc4x3_rc1::clear_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc2
Ifc4x3_rc2::clear_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc3
Ifc4x3_rc3::clear_schema();
#endif
#ifdef HAS_SCHEMA_4x3_rc4
Ifc4x3_rc4::clear_schema();
#endif
// clear any remaining registered schemas
// we pop schemas until map is empty, because map iteration is invalidated after each erasure
while (!schemas.empty()) {
delete schemas.begin()->second;
}
}