genbindings: change simple operator== to use infix syntax

This commit is contained in:
mappu 2024-11-22 18:58:56 +13:00
parent 33c5bbaafb
commit 2a502f24ff
2 changed files with 18 additions and 0 deletions

View File

@ -1026,6 +1026,14 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
callTarget += m.CppCallTarget() + "(" + forwarding + ")"
// Qt 6.8 moved many operator== implementations from class methods
// into global operators.
// By using infix syntax, either can be called
if m.IsReadonlyOperator() && len(m.Parameters) == 1 {
operator := m.CppCallTarget()[8:]
callTarget = "(*self " + operator + " " + forwarding + ")"
}
if m.LinuxOnly {
ret.WriteString(fmt.Sprintf(
"%s %s_%s(%s) {\n"+

View File

@ -348,6 +348,16 @@ func (nm CppMethod) SafeMethodName() string {
return tmp
}
func (nm CppMethod) IsReadonlyOperator() bool {
targ := nm.CppCallTarget()
switch targ {
case "operator==", "operator!=",
"operator<", "operator<=", "operator>", "operator>=":
return true
}
return false
}
type CppEnumEntry struct {
EntryName string
EntryValue string