summaryrefslogtreecommitdiffstats
path: root/generator/headergenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/headergenerator.cpp')
-rw-r--r--generator/headergenerator.cpp24
1 files changed, 19 insertions, 5 deletions
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)