mirror of
https://github.com/mappu/miqt.git
synced 2025-01-20 21:50:38 +00:00
Simplify delete
The subclassing structure in `miqt` is such that nothing ever inherits from `MiqtVirtual` - also, for `MiqtVirtual` to work correctly when Qt deletes an instance part of a tree of widgets, the technique can only be used with types that already have a virtual destructor. Therefore: * make `MiqtVirtual` final to ensure nothing inherits from it by accident * remove `virtual` inheritance of its base class - since there is no MI invonved and no further inheritance, there can also not be any diamond inheritance structures - removing `virtual` makes inheritance a bit cheaper * remove `isSubclass` from `delete` function - C++ already calls the most inherited destructor * mark destructor `override` to verify said assumption
This commit is contained in:
parent
676012fdef
commit
929e4e630a
@ -756,7 +756,7 @@ extern "C" {
|
||||
|
||||
// delete
|
||||
if c.CanDelete {
|
||||
ret.WriteString(fmt.Sprintf("void %s_Delete(%s* self, bool isSubclass);\n", methodPrefixName, methodPrefixName))
|
||||
ret.WriteString(fmt.Sprintf("void %s_Delete(%s* self);\n", methodPrefixName, methodPrefixName))
|
||||
}
|
||||
|
||||
ret.WriteString("\n")
|
||||
@ -865,7 +865,7 @@ extern "C" {
|
||||
|
||||
overriddenClassName := "MiqtVirtual" + strings.Replace(cppClassName, `::`, ``, -1)
|
||||
|
||||
ret.WriteString("class " + overriddenClassName + " : public virtual " + cppClassName + " {\n" +
|
||||
ret.WriteString("class " + overriddenClassName + " final : public " + cppClassName + " {\n" +
|
||||
"public:\n" +
|
||||
"\n",
|
||||
)
|
||||
@ -885,7 +885,7 @@ extern "C" {
|
||||
)
|
||||
} else {
|
||||
ret.WriteString(
|
||||
"\tvirtual ~" + overriddenClassName + "() = default;\n" +
|
||||
"\tvirtual ~" + overriddenClassName + "() override = default;\n" +
|
||||
"\n",
|
||||
)
|
||||
}
|
||||
@ -1217,14 +1217,12 @@ extern "C" {
|
||||
}
|
||||
|
||||
// Delete
|
||||
// If we subclassed, our class destructor is always virtual. Therefore
|
||||
// we can delete from the self ptr without any dynamic_cast<>
|
||||
if c.CanDelete {
|
||||
ret.WriteString(
|
||||
"void " + methodPrefixName + "_Delete(" + methodPrefixName + "* self, bool isSubclass) {\n" +
|
||||
"\tif (isSubclass) {\n" +
|
||||
"\t\tdelete dynamic_cast<" + cppClassName + "*>( self );\n" +
|
||||
"\t} else {\n" +
|
||||
"\t\tdelete self;\n" +
|
||||
"\t}\n" +
|
||||
"void " + methodPrefixName + "_Delete(" + methodPrefixName + "* self) {\n" +
|
||||
"\tdelete self;\n" +
|
||||
"}\n" +
|
||||
"\n",
|
||||
)
|
||||
|
@ -1074,7 +1074,7 @@ import "C"
|
||||
ret.WriteString(`
|
||||
// Delete this object from C++ memory.
|
||||
func (this *` + goClassName + `) Delete() {
|
||||
C.` + goClassName + `_Delete(this.h, C.bool(this.isSubclass))
|
||||
C.` + goClassName + `_Delete(this.h)
|
||||
}
|
||||
|
||||
// GoGC adds a Go Finalizer to this pointer, so that it will be deleted
|
||||
|
Loading…
x
Reference in New Issue
Block a user