mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 00:48:38 +00:00
genbindings: delete either subclass or direct class
This commit is contained in:
parent
fb56258334
commit
6fa97722c5
@ -733,7 +733,7 @@ extern "C" {
|
||||
|
||||
// delete
|
||||
if c.CanDelete {
|
||||
ret.WriteString(fmt.Sprintf("void %s_Delete(%s* self);\n", methodPrefixName, methodPrefixName))
|
||||
ret.WriteString(fmt.Sprintf("void %s_Delete(%s* self, bool isSubclass);\n", methodPrefixName, methodPrefixName))
|
||||
}
|
||||
|
||||
ret.WriteString("\n")
|
||||
@ -1133,13 +1133,16 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
|
||||
|
||||
// Delete
|
||||
if c.CanDelete {
|
||||
ret.WriteString(fmt.Sprintf(
|
||||
"void %s_Delete(%s* self) {\n"+
|
||||
"\tdelete self;\n"+
|
||||
"}\n"+
|
||||
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" +
|
||||
"}\n" +
|
||||
"\n",
|
||||
methodPrefixName, methodPrefixName,
|
||||
))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -730,6 +730,7 @@ import "C"
|
||||
ret.WriteString(`
|
||||
type ` + goClassName + ` struct {
|
||||
h *C.` + goClassName + `
|
||||
isSubclass bool
|
||||
`)
|
||||
|
||||
// Embed all inherited types to directly allow calling inherited methods
|
||||
@ -1028,7 +1029,7 @@ import "C"
|
||||
ret.WriteString(`
|
||||
// Delete this object from C++ memory.
|
||||
func (this *` + goClassName + `) Delete() {
|
||||
C.` + goClassName + `_Delete(this.h)
|
||||
C.` + goClassName + `_Delete(this.h, C.bool(this.isSubclass))
|
||||
}
|
||||
|
||||
// GoGC adds a Go Finalizer to this pointer, so that it will be deleted
|
||||
|
Loading…
Reference in New Issue
Block a user