Skip to content

Commit e677355

Browse files
aschvalbergaothms
authored andcommitted
Add IfcParse::clear_schemas() and individual Ifc___::clear_schema() to clear any resource allocated by registered schemas
Add missing virtual destructors in IfcSchema.h
1 parent 93fd3f9 commit e677355

20 files changed

Lines changed: 169 additions & 27 deletions

src/ifcopenshell-python/ifcopenshell/express/schema_class.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,22 @@ def finalize(self, can_be_instantiated_set):
283283

284284
self.statements.extend(
285285
(
286-
"const schema_definition& %s::get_schema() {" % schema_name_title,
286+
"static std::unique_ptr<schema_definition> schema;",
287+
"",
288+
"void %s::clear_schema() {" % schema_name_title,
289+
" schema.reset();",
290+
"}",
287291
"",
288-
" static const schema_definition* s = %(schema_name)s_populate_schema();" % locals(),
289-
" return *s;",
292+
)
293+
)
294+
295+
self.statements.extend(
296+
(
297+
"const schema_definition& %s::get_schema() {" % schema_name_title,
298+
" if (!schema) {",
299+
" schema.reset(%(schema_name)s_populate_schema());" % locals(),
300+
" }",
301+
" return *schema;",
290302
"}",
291303
"",
292304
"",

src/ifcopenshell-python/ifcopenshell/express/templates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
3939
IFC_PARSE_API static const IfcParse::schema_definition& get_schema();
4040
41+
IFC_PARSE_API static void clear_schema();
42+
4143
static const char* const Identifier;
4244
4345
// Forward definitions

src/ifcparse/Ifc2x3-schema.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12533,9 +12533,16 @@ IfcParse::schema_definition* IFC2X3_populate_schema() {
1253312533
#pragma optimize("", on)
1253412534
#endif
1253512535

12536-
const schema_definition& Ifc2x3::get_schema() {
12536+
static std::unique_ptr<schema_definition> schema;
12537+
12538+
void Ifc2x3::clear_schema() {
12539+
schema.reset();
12540+
}
1253712541

12538-
static const schema_definition* s = IFC2X3_populate_schema();
12539-
return *s;
12542+
const schema_definition& Ifc2x3::get_schema() {
12543+
if (!schema) {
12544+
schema.reset(IFC2X3_populate_schema());
12545+
}
12546+
return *schema;
1254012547
}
1254112548

src/ifcparse/Ifc2x3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct Ifc2x3 {
4444

4545
IFC_PARSE_API static const IfcParse::schema_definition& get_schema();
4646

47+
IFC_PARSE_API static void clear_schema();
48+
4749
static const char* const Identifier;
4850

4951
// Forward definitions

src/ifcparse/Ifc4-schema.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15071,9 +15071,16 @@ IfcParse::schema_definition* IFC4_populate_schema() {
1507115071
#pragma optimize("", on)
1507215072
#endif
1507315073

15074-
const schema_definition& Ifc4::get_schema() {
15074+
static std::unique_ptr<schema_definition> schema;
15075+
15076+
void Ifc4::clear_schema() {
15077+
schema.reset();
15078+
}
1507515079

15076-
static const schema_definition* s = IFC4_populate_schema();
15077-
return *s;
15080+
const schema_definition& Ifc4::get_schema() {
15081+
if (!schema) {
15082+
schema.reset(IFC4_populate_schema());
15083+
}
15084+
return *schema;
1507815085
}
1507915086

src/ifcparse/Ifc4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct Ifc4 {
4444

4545
IFC_PARSE_API static const IfcParse::schema_definition& get_schema();
4646

47+
IFC_PARSE_API static void clear_schema();
48+
4749
static const char* const Identifier;
4850

4951
// Forward definitions

src/ifcparse/Ifc4x1-schema.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15472,9 +15472,16 @@ IfcParse::schema_definition* IFC4X1_populate_schema() {
1547215472
#pragma optimize("", on)
1547315473
#endif
1547415474

15475-
const schema_definition& Ifc4x1::get_schema() {
15475+
static std::unique_ptr<schema_definition> schema;
15476+
15477+
void Ifc4x1::clear_schema() {
15478+
schema.reset();
15479+
}
1547615480

15477-
static const schema_definition* s = IFC4X1_populate_schema();
15478-
return *s;
15481+
const schema_definition& Ifc4x1::get_schema() {
15482+
if (!schema) {
15483+
schema.reset(IFC4X1_populate_schema());
15484+
}
15485+
return *schema;
1547915486
}
1548015487

src/ifcparse/Ifc4x1.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct Ifc4x1 {
4444

4545
IFC_PARSE_API static const IfcParse::schema_definition& get_schema();
4646

47+
IFC_PARSE_API static void clear_schema();
48+
4749
static const char* const Identifier;
4850

4951
// Forward definitions

src/ifcparse/Ifc4x2-schema.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15808,9 +15808,16 @@ IfcParse::schema_definition* IFC4X2_populate_schema() {
1580815808
#pragma optimize("", on)
1580915809
#endif
1581015810

15811-
const schema_definition& Ifc4x2::get_schema() {
15811+
static std::unique_ptr<schema_definition> schema;
15812+
15813+
void Ifc4x2::clear_schema() {
15814+
schema.reset();
15815+
}
1581215816

15813-
static const schema_definition* s = IFC4X2_populate_schema();
15814-
return *s;
15817+
const schema_definition& Ifc4x2::get_schema() {
15818+
if (!schema) {
15819+
schema.reset(IFC4X2_populate_schema());
15820+
}
15821+
return *schema;
1581515822
}
1581615823

src/ifcparse/Ifc4x2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ struct Ifc4x2 {
4444

4545
IFC_PARSE_API static const IfcParse::schema_definition& get_schema();
4646

47+
IFC_PARSE_API static void clear_schema();
48+
4749
static const char* const Identifier;
4850

4951
// Forward definitions

0 commit comments

Comments
 (0)