summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp3
-rw-r--r--generator/headergenerator.cpp24
2 files changed, 20 insertions, 7 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 28ab0b71..c249eb21 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -2721,8 +2721,7 @@ void CppGenerator::writeGetterFunction(QTextStream& s, const AbstractMetaField*
#ifdef AVOID_PROTECTED_HACK
if (metaField->isProtected())
- cppField = QString("(%1(%2*)%3)->%4()")
- .arg(useReference ? '&' : ' ')
+ cppField = QString("((%1*)%2)->%3()")
.arg(wrapperName(metaField->enclosingClass()))
.arg(cpythonWrapperCPtr(metaField->enclosingClass(), "self"))
.arg(protectedFieldGetterName(metaField));
diff --git a/generator/headergenerator.cpp b/generator/headergenerator.cpp
index 9a28cdb9..bb8f341a 100644
--- a/generator/headergenerator.cpp
+++ b/generator/headergenerator.cpp
@@ -47,13 +47,27 @@ void HeaderGenerator::writeCopyCtor(QTextStream& s, const AbstractMetaClass* met
void HeaderGenerator::writeProtectedFieldAccessors(QTextStream& s, const AbstractMetaField* field) const
{
- QString fieldType = field->type()->cppSignature();
+ AbstractMetaType *metaType = field->type();
+ QString fieldType = metaType->cppSignature();
QString fieldName = field->enclosingClass()->qualifiedCppName() + "::" + field->name();
- s << INDENT << "inline " << fieldType << ' ' << protectedFieldGetterName(field) << "()";
- s << " { return " << fieldName << "; }" << endl;
- s << INDENT << "inline void " << protectedFieldSetterName(field) << '(' << fieldType << " value)";
- s << " { " << fieldName << " = value; }" << endl;
+ // Force use of pointer to return internal variable memory
+ bool useReference = (!metaType->isConstant() &&
+ !metaType->isEnum() &&
+ !metaType->isPrimitive() &&
+ metaType->indirections() == 0);
+
+
+ // Get function
+ s << INDENT << "inline " << fieldType
+ << (useReference ? '*' : ' ')
+ << ' ' << protectedFieldGetterName(field) << "()"
+ << " { return "
+ << (useReference ? '&' : ' ') << "this->" << fieldName << "; }" << endl;
+
+ // Set function
+ s << INDENT << "inline void " << protectedFieldSetterName(field) << '(' << fieldType << " value)"
+ << " { " << fieldName << " = value; }" << endl;
}
void HeaderGenerator::generateClass(QTextStream& s, const AbstractMetaClass* metaClass)